Js context introduction
01 November 2014
Origin https://www.youtube.com/watch?v=fjJoX9F_F5g
This in window context
This In Global Function
What is this
This in Object
Three methods to change context
Method 1
var obj = {
foo : function(){
console.log(this === window);
}
};
//call
obj.foo.call(window);
Method 2
var obj = {
foo : function(){
console.log(this === window);
}
};
//call
obj.foo.apply(window);
Method 3
var obj = {
foo : function(){
console.log(this === window);
}
};
//call
var windowFoo = obj.foo.bind(window);
windowFoo();
Bind to change Context
Element context in event
Get parent context by reference variable**
Get parent context by methd bind
blog comments powered by Disqus