.. Object.rst --- .. .. Description: .. Author: Hongyi Wu(吴鸿毅) .. Email: wuhongyi@qq.com .. Created: 五 8月 2 20:01:34 2019 (+0800) .. Last-Updated: 六 8月 3 21:43:57 2019 (+0800) .. By: Hongyi Wu(吴鸿毅) .. Update #: 2 .. URL: http://wuhongyi.cn ################################################## 对象 ################################################## .. code-block:: JavaScript function Person(first, last, age, eyecolor) { this.firstName = first; this.lastName = last; this.age = age; this.eyeColor = eyecolor; } var myFather = new Person("Bill", "Gates", 62, "blue"); var myMother = new Person("Steve", "Jobs", 56, "green"); 有时,希望向所有给定类型的已有对象添加新属性(或方法)。有时,希望向对象构造器添加新属性(或方法)。 JavaScript **prototype** 属性允许您为对象构造器添加新属性: .. code-block:: JavaScript function Person(first, last, age, eyecolor) { this.firstName = first; this.lastName = last; this.age = age; this.eyeColor = eyecolor; } Person.prototype.nationality = "English"; Person.prototype.name = function() { return this.firstName + " " + this.lastName; }; .. .. Object.rst ends here