Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hasOwnProperty vs in #7

Open
leslie1943 opened this issue Nov 19, 2020 · 0 comments
Open

hasOwnProperty vs in #7

leslie1943 opened this issue Nov 19, 2020 · 0 comments
Labels
documentation Improvements or additions to documentation

Comments

@leslie1943
Copy link
Owner

  • hasOwnPropery: 不会去判断原型变量和方法
  • in: 会去判断原型变量和方法
var data = {
    name: 'leslie',
    compony: 'xxxx'
}
// hasOwnProperty 方法不会去判断原型
console.info(data.hasOwnProperty("name")) // true
console.info(data.hasOwnProperty("hasOwnProperty")) // false
// in 方法会去判断原型
console.info('name' in data) // true
console.info('hasOwnProperty' in data) // true
// getOwnPropertyNames
console.info(Object.getOwnPropertyNames(data)) // ['name','company']
// keys
console.info(Object.keys(data)) // ['name','company']
@leslie1943 leslie1943 added help wanted Extra attention is needed documentation Improvements or additions to documentation and removed help wanted Extra attention is needed labels Nov 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant