rol*_*ack 1 javascript arrays asynchronous
因此,我一直在研究JavaScript实际上是单线程的,即使它似乎是多线程的(或者至少我是这样理解的),我想知道以下功能是否可以保证在其他功能之前完成叫做。
我相当确定它是,但是调用push()使我担心,在调用它时,可能会先执行其他一些功能。话虽这么说,我想不出会运行任何长时间运行的代码push()。
// adds a new node to children, after checking if its UID is not in childrenAdded
this.addChild = function(newChild) {
if (!_this._childrenAdded[newChild.uid]) {
_this._childrenAdded[newChild.uid] = true;
_this._children.push(newChild);
}
}
Run Code Online (Sandbox Code Playgroud)