1

Ok, Im wondering if it is possible to transfer the reference of the object to the functions. If you dont understand what im trying to say, this might help:

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

So for the update function, I want to be able to do something like:

this.update = function() {
    var ta = $(edit)[0].value, dy = $(dyna)[0].contentDocument;
    if (old !== ta) {
        $(dy).text(ta);
        old = ta;
    }
    window.setTimeout(update, 150);
}

And it gives me the variables(edit, dyna, old) from the Editor object. Thanks.

2 Answers 2

2

Why aren't you just using the this prefix. So this.edit[0].value?

Maybe I am missing something as it's late here...

Sign up to request clarification or add additional context in comments.

Comments

1

this inside your function refers to the object of the anonymous base function you have created.

Use this.propertyName to access its properties.

var ta = $(this.edit)[0].value, dy = $(this.dyna)[0].contentDocument;

1 Comment

Thanks. That was not very smart of me, but I was trying to fix a much larger problem and got confused. Back on track...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.