为什么这个JavaScript OO错了?
我将以简单的方式放置我的代码,但如果有任何好的灵魂希望帮助代码是在Github上/lib/inmotion/editor.js(line 99)
editor.js内
function Editor(){
var instance = this;
this.key_frames = [] // a list of key frames
this.kf = null // the current KeyFrame
function notice_click( click ){
instance.kf.add_bone( 1 ) // <-- error here
// instance.kf.list.push( 1 ) // <-- this works, but is incomplete
}
}
key_frame.js
function KeyFrame(){
instance = this
instance.changed = false // for the redraw :)
instance.list = []
function add_bone( bone ){
instance.list.push( bone )
instance.changed = true
return true
}
}
我的程序有一个唯一的Editor实例,它有很多KeyFrames实例。
每个KeyFrame都有很多骨头。
所以总有一个活动的KeyFrame,由Editor.kf实例定义
由于我只有一个kf,我可以毫无问题地为那个添加骨骼,但是当我添加更多KeyFrames时,我只能将add_bone添加到我创建的最后一个kf中!为什么?
如果我不够清楚,我道歉,怀疑
没有找到相关结果
已邀请:
2 个回复
席陋临拈
对象缺少
,它应该如下所示:
没有
关键字你定义或覆盖
,一个全局变量,而不是你想要的对象的本地变量:)
粱委教