【发布时间】:2014-08-25 22:03:14
【问题描述】:
我有一个如下的对象设置:
var StartScreenLayer = cc.Layer.extend({
ctor: function () {
this._super();
// this function can call createBackground!
this.createBackground();
},
callCreateBackgroundToo: function () {
// I can call createBackground too!
this.createBackground();
},
createBackground: function () {
});
如何安排它以使 createBackground 是私有的,但其他其他对象不能调用类似 screenLayer.createBackground() 的东西并在对象上抛出 createBackground is undefined 类型错误?
【问题讨论】:
-
看看JavaScript private methods。您可能想使用
createBackground.call(this)来回答一些问题。 -
嘿,我看了看,看起来你必须跳过一堆圈才能让它工作。我刚刚决定使用现有的约定,即在函数前加上下划线。
-
下划线前缀确实也是一个很好且易于使用的解决方案。仅供参考其他解决方案may not be that hard(但可能无法访问)
-
哦,哇,我喜欢你的例子 2!将其添加为答案,我明天会接受。
标签: javascript html cocos2d-x cocos2d-js