1创建函数的实例A
2.当通过.来引用对象A的函数或者属性时,如果对象没有此函数或者属性,将访问对象的prototype属性对象,在prototype中查找相关函数或者属性。
例子:
- /**
- * Person函数对象
- *
- * @return
- */
- function Person() {
- this.name = 'Kyle';
- this.sex = 'M';
- }
- Person.prototype.name = 'ZhaoHui';
- Person.prototype.age = '20';
- var person = new Person;// 创建Person对象的副本person
- alert(person.sex); // 输出sex
- alert(person.name); // 输出name.this.name ?Person.prototype.name?
- alert(person.age); // 输出age