Skip to content

Instantly share code, notes, and snippets.

@myvyang
Last active April 22, 2023 13:06
Show Gist options
  • Save myvyang/4bde49c5fbc73dbcf451c5f0928c3dd9 to your computer and use it in GitHub Desktop.
Save myvyang/4bde49c5fbc73dbcf451c5f0928c3dd9 to your computer and use it in GitHub Desktop.
ES6中 __proto__ 和 prototype 的关系

1. 只有函数有 prototype 属性。默认情况下,func.ptototype = {constructor: func} ,即 func.ptototype.constructor == func
2. 任何对象都有 __proto__ 属性,指向自己的 [[Prototype]] ,即原型链的上一层
3. 例如,var c = new func() ,则 c.__proto__ === func.ptototype 
4. 如果 var c = 1 ,约等于 var c = Number(1) ,因此 c.__proto__ === Number.prototype 
5. 可以看到 x.__proto__ 永远都不会是一个函数,但是永远都会是某个 func.prototype

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment