//全局的函数调用
var name="Helen";
function Name(){
console.log(this.name);
}
Name();
//对象方法的调用
function showage(){
console.log(this.name);
}
var obj={
name:"Jone",
show:showage
}
obj.show();
//构造函数
function Hello(name,job){
this.name=name;
this.job=job;
this.infoall=function(){
console.log(this.name+"是"+this.job);
}
}
var person=new Hello("Jochi","警察");
person.infoall();
//apply()改变函数的调用对象,apply()默认调用全局对象,apply(obj)指定调用obj对象
var x=0;
function change(){
console.log(this.x);
}
var obj={
x:1,
m:change,
}
obj.m();//1
obj.m.apply();//0
obj.m.apply(obj);//0