1

わかりました、オブジェクトの参照を関数に転送できるかどうか疑問に思っています。私が何を言おうとしているのか理解できない場合は、これが役立つかもしれません:

//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);
}

そして、オブジェクトから変数 (edit、dyna、old) を取得しEditorます。ありがとう。

4

2 に答える 2

2

this接頭辞だけを使用していないのはなぜですか。それでthis.edit[0].value

ここで遅くなったので、何かが足りないのかもしれません...

于 2010-06-26T03:04:01.577 に答える
1

this関数内では、作成した無名ベース関数のオブジェクトを参照します。

this.propertyNameプロパティにアクセスするために使用します。

var ta = $(this.edit)[0].value, dy = $(this.dyna)[0].contentDocument;
于 2010-06-26T03:03:21.930 に答える