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
var Person = function(name){ this.name = name; } Person.prototype.getName = function(){ return this.name; } var Bob = new Person('Bob'); // 这里 new Person('Bob') 发生了什么?
下面我们来探探: 当代码 new Person('Bob') 执行时:
{ }
[[prototype]]
this
function New(func) { var res = {}; if (func.prototype !== null) { res.__proto__ = func.prototype; } var ret = func.apply(res, Array.prototype.slice.call(arguments, 1)); if ((typeof ret === "object" || typeof ret === "function") && ret !== null) { // typeof null === 'object' return ret; } return res; }
最后附上一张原型链的图:
The text was updated successfully, but these errors were encountered:
No branches or pull requests
下面我们来探探:
当代码 new Person('Bob') 执行时:
{ }
,这个对象的类型是 object;[[prototype]]
(i.e proto )属性为构造函数的原型对象;this
关键字指向这个新对象,执行构造函数;代码模拟
最后附上一张原型链的图:
The text was updated successfully, but these errors were encountered: