var o_1 = {
age:12,
say:function(){
function callback(){
return this.age;
}
func_1(callback);
}
};
function func_1(callback){
var name = "xiaoming";
console.log(name + " is " + callback() + " years old.");
}
o_1.say();
var o_2 = {
age:12,
say:function(){
function callback(){
return o_2.age;
}
func_2(callback);
}
};
function func_2(callback){
var name = "xiaoming";
console.log(name + " is " + callback() + " years old.");
}
o_2.say();
var o_3 = {
age:12,
say:function(){
var callback = () =>this.age;
func_3(callback);
}
};
function func_3(callback){
var name = "xiaoming";
console.log(name + " is " + callback() + " years old.");
}
o_3.say();
var o_4 = {
age:12,//终点5
say:function(){
function callback(that){//途径3
return that.age;//途径4
}
func_4(this,callback);//起点1
}
};
function func_4(that,callback){//途径2
var name = "xiaoming";
console.log(name + " is " + callback(that) + " years old.");//途径2
}
o_4.say();