Skip to content

Instantly share code, notes, and snippets.

View JunPyoL22's full-sized avatar

이 준표 jplee JunPyoL22

  • SPACEWALK
  • Seoul
View GitHub Profile
function price() {
return this.price;
}
function howMuchIsIt() {
var ans = "It's " + price.call( this ) + ' worth';
console.log( ans );
}
var productA = {
var obj = {
x:10,
printX:function(){
console.log(this.x);
}
}
var printx1 = obj.printX;
printx1() // => undefined
var printx2 = printx1.bind(obj)
var indirect = { name: 'indirect function invocation' };
function concatName(string) {
console.log(this === indirect); // => true
return string + this.name;
}
// Indirect invocations
concatName.call(indirect, 'Hello '); // >> 'Hello indirect function invocation'
concatName.apply(indirect, ['Bye ']); // >> 'Bye indirect function invocation'
function thisAtConstructorInvoke() {
console.log(this instanceof thisAtConstructorInvoke); // >> true
this.property = "default value";
}
var instance = new thisAtConstructorInvoke();
instance.property; // >> default value
var methodInvoke = {
des : "calling function owned by object",
mean : function() {
console.log(this===window);
console.log('method invocation is a ' + this.des);
}
}
var seperated_method = methodInvoke.mean
seperated_method() // >> true, 'method invocation is a undefined'
var methodInvoke = {
des : "calling function owned by object",
mean : function() {
console.log(this===methodInvoke);
console.log('method invocation is a ' + this.des);
}
}
methodInvoke.mean(); // >> true, method invocation is a calling function owned by object
function thisAtfunctionInvoke(){
console.log(this===window);
this.number = 20
}
thisAtFunctionInvoke(); // >> true
console.log(window.number===20); // >> true
console.log(this === window); // >> true
function thisAtfunctionInvokeInStrictMode(){
'use strict';
console.log(this===undefined);
this.number = 20
}
thisAtfunctionInvokeInStrictMode(); // >> true
console.log(window.number===20); // >> false