首页 > 试题广场 >

var account = { ph...

[不定项选择题]
var account = {
    phone: "1234567",
    getPhone: function() {
        return this.phone;
    }
};
var mycount = account.getPhone;
console.log(account.getPhone());
console.log(mycount());

  • 1234567,undefined
  • undefined,undefined
  • undefined, 1234567
  • 1234567,1234567
this的指向是看调用时的对象,第一个是account调用,所以this指向account,account中有getPhone这个方法
第二个是mycount调用,它是account.getPhone的实例对象,继承了getPhone这个方法,mycount是挂载在window上的,所以this指向window
发表于 2019-06-26 22:12:15 回复(0)
第一个打印 主体是account对象,所以this指向account对象,打印1234567
第二个打印 主体是window, 所以this指向window, 全局下没有phone  所以打印undefined
发表于 2019-05-15 11:12:49 回复(0)
声明变量,输出函数表达式(),所以为undefined
发表于 2019-05-13 10:43:33 回复(0)