JavaScript 参考手册
JavaScript prototype 属性
适用 prototype 属性给对象添加属性
源代码:
点击运行 »
<script> function employee(name, jobtitle, born) { this.name = name; this.jobtitle = jobtitle; this.born = born; } var fred = new employee("Fred Flintstone", "Caveman", 1970); employee.prototype.salary = null; fred.salary = 20000; document.write(fred.salary); </script>
运行结果:
点击运行 »