js中對象冒充示例
javascript對象冒充示例 <script type="text/javascript">
function Animal(name,age){
this.name=name;
this.age=age;
this.eat=function(){
alert("動物可以吃東西");
}
}
function Dog(name,age){
//把Animal構造函數賦給this.an
this.an=Animal;
//運行調用@?。。?!非常重要
this.an(name,age);
}
var dog=new Dog("小白",2);
alert(dog.name);
dog.eat();
</script>
posted on 2013-04-12 15:44 何云隆 閱讀(1770) 評論(0) 編輯 收藏 所屬分類: JS