We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
每个函数创建的时候,其内部会初始化一个prototype属性,prototype属性指向一个对象,这个对象正是调用其构造函数创建的实例的原型。
function Person(){} console.log(typeof Person.prototype)// object
__proto__
当访问一个对象的属性时,如果自己内部没有找到该属性,就会向上访问原型对象,一直检索到Object内置对象,从而形成一条由__proto__连接的原型链。
function Person(){} Person.prototype.name = 'zhangsan'; Person.prototype.age = 22; Person.prototype.say = function(){ console.log(this.name+','+this.age); } var p1 = new Person(); var p2 = new Person(); p2.name = "lisi"; p2.say();// lisi,22 p1.say();// zhangsan,22
The text was updated successfully, but these errors were encountered:
可以留个联系方式吗?
Sorry, something went wrong.
No branches or pull requests
原型(prototype)
概念
每个函数创建的时候,其内部会初始化一个prototype属性,prototype属性指向一个对象,这个对象正是调用其构造函数创建的实例的原型。
原型链(
__proto__
)概念
当访问一个对象的属性时,如果自己内部没有找到该属性,就会向上访问原型对象,一直检索到Object内置对象,从而形成一条由__proto__连接的原型链。
The text was updated successfully, but these errors were encountered: