用prototype继承整个对象

来源:互联网 发布:java免费开源商城系统 编辑:程序博客网 时间:2024/06/05 10:44

what if we want to inherit an entire object?

<html><head><title>Some Page</title></head><body><script>// Declare two objects - we're going to want Lion to// inherit from catfunction cat() {this.eyes = 2;this.legs = 4;this.diet = 'carnivore';return true;}function lion() {this.mane = true;this.origin = 'Africa';return true;}// Now comes the inheritancelion.prototype = new cat();// We can now obtain lion.dietvar simba = new lion();var simba_diet = simba.diet;document.write(simba_diet);</script></body></html>

原文:

http://nefariousdesigns.co.uk/object-oriented-javascript.html

原创粉丝点击