控制台日志消息没有显示在浏览器控制台



在我的Backbone视图中有这个函数,用于通过后端API创建一个新对象:

// *** called when remote hardware signal triggered
createConference: function () {
var self = this;
console.log("ScheduleLocationArea.js - createConference() ")
const startTime = performance.now();
this.sysLocation.create().then((response) => {
self.model.collection.add(response);
});
const duration = performance.now() - startTime;
console.log(`PERFORMANACE CHECK: ScheduleLocationArea.js - the function createConference() took ${duration}ms`);
},

调用这个函数:

// called from within createConference
async create() {
console.log("Location.js - create() ")
const startTime = performance.now();
return await this.sync('create', this, {
url: this.create.url(this.id)
}, { silent: true });
const duration = performance.now() - startTime;
console.log(`PERFORMANACE CHECK: Location.js - the function create() took ${duration}ms`);
},

正如你所看到的,我正在尝试检查性能问题。

但是由于某种原因,我不知道,它没有完成create()函数。我从未见过那个函数的PERFORMANACE CHECK

这是我的控制台输出:

ScheduleLocationArea.js - createConference() 
Location.js:22 Location.js - create() 
ScheduleLocationArea.js:269 PERFORMANACE CHECK: ScheduleLocationArea.js - the function createConference() took 1.7000000476837158ms

浏览器会很快地写出上面所有的控制台消息。

尽管它说只花了1.7ms…实际上只需要3秒。

所以我不明白为什么要花这么长时间,为什么不写出create()函数的性能数字。

我做错了什么吗?

谢谢!

// called from within createConference
async create() {
console.log("Location.js - create() ")
const startTime = performance.now();
return await this.sync('create', this, {
url: this.create.url(this.id)
}, { silent: true });
const duration = performance.now() - startTime;
console.log(`PERFORMANACE CHECK: Location.js - the function create() took ${duration}ms`);
},

// called from within createConference
async create() {
console.log("Location.js - create() ")
const startTime = performance.now();
const newUrl = await this.sync('create', this, {
url: this.create.url(this.id)
}, { silent: true });
const duration = performance.now() - startTime;
console.log(`PERFORMANACE CHECK: Location.js - the function create() took ${duration}ms`);
return newUrl;
},

这将允许你的函数在返回创建的值之前显示性能日志。

在第一个代码片段中调用console.log之前从函数返回。return语句后的任何代码都不会运行:

// called from within createConference
async create() {
console.log("Location.js - create() ")
const startTime = performance.now();
return await this.sync('create', this, {
url: this.create.url(this.id)
}, { silent: true });
// this following code never runs as screate(0 has returned already
const duration = performance.now() - startTime;
console.log(`PERFORMANACE CHECK: Location.js - the function create() took ${duration}ms`);
},

相关内容

  • 没有找到相关文章

最新更新