What will be the output of the following code?
What will be the output of the following code?
var myObject = {
foo: "bar",
func: function() {
var self = this;
console.log("outer func: this.foo = " + this.foo);
console.log("outer func: self.foo = " + self.foo);
(function() {
console.log("inner func: this.foo = " + this.foo);
console.log("inner func: self.foo = " + self.foo);
}());
}
};
myObject.func();
The output of the above code will be:
outer func: this.foo = bar
outer func: self.foo = bar
inner func: this.foo = undefined
inner func: self.foo = bar
Here's the explanation for the output:
outer func: this.foo = bar - In the context of myObject.func(), this refers to myObject. Therefore, this.foo is equivalent to myObject.foo, which is "bar".Can you describe the main difference between a .forEach loop and a .map() loop and why you would pick one versus the other?
Xem chi tiếtCan you give an example for destructuring an object or an array in ES6?
Xem chi tiếtCan you give an example of a curry function and why this syntax offers an advantage?
Xem chi tiếtĐăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.