1
好吧,我想知道是否有可能将对象的引用传递给函数。如果你不明白我尝试说,这可能帮助:从成员方法内访问JavaScript对象引用
//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);
}
,这让我的变量(编辑,dyna,旧)从Editor
对象。 谢谢。
谢谢。这对我来说不是很聪明,但我试图解决一个更大的问题并且感到困惑。回到正轨... – tcooc 2010-06-26 03:10:56