Javascriptのthis使い方
1.グローバル変数
var value="0″;
function startnews24(){
var value="1″;
console.log(this.value); //0
console.log(value); //1
}
startnews24();
2.コンストラクター関数
var value="window";
function startnews24(){
this.value=1;
this.show=function(){
console.log(this.value)
}
}
var m=new startnews24();
console.log(m.value); //1
m.show(); //1
3.callとapply
var p="456″;
function f1(){
this.p="123″;
}
function f2() {
console.log(this.p);
}
f2(); //456
f2.call(f1()); //123
f2.apply(f1()); //123
4.オブジェクトメソッドの呼び出し
var value="father";
function startnews24(){}
startnews24.value="child";
startnews24.get=function(){console.log(this.value)};
startnews24.show=function(){console.log(value)};
startnews24.get(); //child
startnews24.show(); //father