新人一枚,在读 范例集合时。
在 menu.js 中下面的 _isLoadingScene 与 showDebugDraw 在哪定义的?
this._isLoadingScene = false;
this.showDebugDraw = false;
就是看不明白。小白请多多关照!谢谢〜〜〜
新人一枚,在读 范例集合时。
在 menu.js 中下面的 _isLoadingScene 与 showDebugDraw 在哪定义的?
this._isLoadingScene = false;
this.showDebugDraw = false;
就是看不明白。小白请多多关照!谢谢〜〜〜
声明方式2:
(1) test = 5;
说明:没有使用var,直接给标识符test赋值,这样会隐式的声明了全局变量test。即使该语句是在一个function内,当该function被执行后test变成了全局变量。
是不是 采用了这种方式定义了?
js 还真是神奇!
var let const
_isLoadingScene showDebugDraw不需要定义,这里是给对象的属性赋值。
关于JavaScript对象,你可以看:
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Working_with_Objects
首先非常感谢各位的答复。
这里应该是用了 下面例子里的方法定义了对象的属性:
创建直接的实例
这个例子创建了对象的一个新实例,并向其添加了四个属性:
实例
person=new Object();
person.firstname=“Bill”;
person.lastname=“Gates”;
person.age=56;
person.eyecolor=“blue”;
资料 :http://www.w3school.com.cn/js/js_objects.asp
所以 js 可以先 new 一个对象出来再向它添加属性 。
为了验证 我在 menu.js 的
onLoad: function () 方法的前面和后面把对象的所有属性列出来:
onLoad: function () {
console.log(Object.keys(this));
........
........
console.log(Object.keys(this));
},
前面的输出 :
Simulator: JS: _name,_objFlags,node,_id,__scriptAsset,_enabled,text,readme,btnInfo,btnBack,testList,__instanceId,__eventTargets
后面的输出:
Simulator: JS: _name,_objFlags,node,_id,__scriptAsset,_enabled,text,readme,btnInfo,btnBack,testList,__instanceId,__eventTargets,_isLoadingScene,showDebugDraw,currentSceneUrl,contentPos,isMenu,sceneList
理解应该就是这样了吧?