<script type="text/javascript"> /* * 继承的最佳实践 * 对象冒充继承属性,原型继承方法 */ function Star(){ this.type = 1; this.name = 'star'; } Star.prototype.getName = function(){ return this.name; } function Sun(){ Star.call(this); this.type = 2; this.age = 10000; } Sun.prototype = new Star(); Sun.prototype.getAge = function(){ return this.age; } var s = new Sun(); show(s); function show(obj){ var h = ''; for(var i in obj){ h += i+': '+obj[i]+'\n'; } alert(h); } </script>
javascript继承
最新推荐文章于 2025-06-15 14:00:34 发布