- 创建一个不可修改的属性
var MyClass = cc.Node.extend({
ctor : function(){
this._super()
this.actorId = 10;
cc.log(this.actorId);
}
});
cc.defineGetterSetter(MyClass.prototype, "actorId", function () {
return this._actorId;
}, function () {
this._actorId = 5; //不可写入
});
- 作为对比创建一个可修改属性
var MyClass = cc.Node.extend({
ctor : function(){
this._super()
this.actorId = 10;
cc.log(this.actorId);
}
});
cc.defineGetterSetter(MyClass.prototype, "actorId", function () {
return this._actorId;
}, function (val) {
this._actorId = val; //可写入
});