好的,我想知道是否可以将对象的引用转移到函数中。如果您不明白我想说什么,这可能会有所帮助:
//so i declare the variable `Editor`
var Editor = new (function(e, d){
this.edit = e;
this.dyna = d;
this.old = ""; //and set these variables inside the object
this.update = function() {
var ta = $(Editor.edit)[0].value, dy = $(Editor.dyna)[0].contentDocument;
//what i want is to be able to refer to the variables (ie. "edit") without using "Editor."
if (Editor.old !== ta) {
$(dy).text(ta);
Editor.old = ta;
}
window.setTimeout(Editor.update, 150);
}
return this;
})("editor","dynamic");
因此,对于更新功能,我希望能够执行以下操作:
this.update = function() {
var ta = $(edit)[0].value, dy = $(dyna)[0].contentDocument;
if (old !== ta) {
$(dy).text(ta);
old = ta;
}
window.setTimeout(update, 150);
}
它给了我Editor
对象中的变量(编辑、动态、旧)。谢谢。