simon
simon

Reputation: 944

Setting Events in a class that utilize a later mentioned Prototype?

When I reach the console.log() its returning window.

How can I get the element under consideration?

let builder = function(){
    this.box = $(`<div id="box" class="box">`);
    this.inputcontainer = $(`<div id="inputcontainer" class="inputcontainer">`).appendTo(this.box);
    this.textarea = $(`<textarea id="textarea"></textarea>`).appendTo(this.inputcontainer);
    this.textarea.on("change keyup keydown input paste", this.postmsg);
    this.chat.appendTo($('body'));
}

//someothercode

builder.prototype.postmsg = (e) => {
    console.log(this); // returns window when I need it to be referencing textarea
}

let instance = new builder();

Upvotes: 1

Views: 31

Answers (1)

ggirodda
ggirodda

Reputation: 780

builder.prototype.postmsg = function(e){
    console.log(this.textarea);
}

Upvotes: 1

Related Questions