W
W
websiller2017-09-01 11:20:00
JavaScript
websiller, 2017-09-01 11:20:00

How to reference current object from object in js prototype?

function JClass() {
  var t = 1;
};
JClass.prototype.option = {
  newo:function(){
    alert(/*Как здесь сослаться на t текущего объекта*/);
  }
};

new JClass().option.newo(); // Должен вывести значение t

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Kornilov, 2017-09-01
@KorniloFF

It's easiest to do this:

function JClass() {
  this.t = 1;
};

alert((new JClass()).t);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question