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
new
Object
new Object()
{}
已解决:创建多个对象的问题 未解决:对象识别
function createPerson(){ var o = new Object(); o.name = name; o.say = function(){ console.log(this.name) } } var p1 = createPerson();
问题:每个方法都要在每个实例上重新创建一遍
function Person(name){ this.name = name; this.say = function(){ console.log(this.name) } } var p1 = new Person('leon');
创建的每个函数都有一个 prototype 属性,这个属性是一个指针,指向一个对象。
prototype
function Person(){ } Person.prototype.name = 'leon' var p1 = name Person()
The text was updated successfully, but these errors were encountered:
No branches or pull requests
一、创建Object实例的方式
new
操作符后跟Object
构造函数,如:二、创建对象
A、工厂模式
B、构造函数模式
C、原型模式
创建的每个函数都有一个
prototype
属性,这个属性是一个指针,指向一个对象。The text was updated successfully, but these errors were encountered: