<script language="JavaScript"> function Person(name) { this.name = name; } // 实例化对象 var xiaoming = new Person("小明"); // 增加 age 属性 Person.prototype.age = null; xiaoming.age = 25; document.write( "我叫" + xiaoming.name + ",今年" + xiaoming.age + "岁。" ); </script>
运行该例子,输出:
我叫小明,今年25岁。