Answer the question
In order to leave comments, you need to log in
Javascript objects?
Guys, a question in the studio! ;)
var test = {
getText: function(some) {
},
otherSome: function(someOther) {
this.getText(); // Не работает
test.getText(); // Работает
}
}
Answer the question
In order to leave comments, you need to log in
Everything is working.
plnkr.co/edit/T34u0iak4WurB9zdjcq6?p=preview
Why is that?this refers to the context in which the function was called
test.otherSome(); //контекст - test
test.otherSome.call(null); //контекст - null
new test.otherSome(); //контекст - новый объект унаследованный от test.otherSome.prototype
(0, test.otherSome)(); //контекст - undefined (в strict mode) или глобальный объект (не в strict mode)
({ otherSome: test.otherSome }).otherSome(); //контекст - объект который в скобочках
It will be useful to read about it:
https://learn.javascript.ru/objects-more
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question