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