Skip to content
This repository has been archived by the owner on Oct 24, 2018. It is now read-only.

第三章:53页,name的特殊情况 #1

Closed
wmh1106 opened this issue Aug 3, 2017 · 2 comments
Closed

第三章:53页,name的特殊情况 #1

wmh1106 opened this issue Aug 3, 2017 · 2 comments

Comments

@wmh1106
Copy link

wmh1106 commented Aug 3, 2017

person.firstName.name 书上写是get firstName
但是我运行结果是 undefined
这是书里写错了吗?

@hyy1115
Copy link
Owner

hyy1115 commented Aug 3, 2017

估计这种获取方式不对,你可以使用其他方式读取:

var person = {
  get firstName() {
    return "Nicholas"
  },
  sayName: function() {
    console.log(this.name)
  }
}
var descriptor = Object.getOwnPropertyDescriptor(person, "firstName")
console.log(descriptor.get.name)

@TYRMars
Copy link

TYRMars commented Aug 7, 2017

关于firstName是person的一个属性,它的值是Nicholas。因为这是个字符串,所以没有name属性也就是undefined。

@hyy1115 hyy1115 closed this as completed Sep 21, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants