原型链的问题

2017-06-21 12:00:00
admin
原创
469
<!DOCTYPE html>
<html>
<head>
    <title>Prototype Chaining Example 4</title>
    <script type="text/javascript">
                    
        function SuperType(){
            this.colors = ["red", "blue", "green"];
        }

        function SubType(){            
        }
        
        //inherit from SuperType
        SubType.prototype = new SuperType();

        var instance1 = new SubType();
        instance1.colors.push("black");
        alert(instance1.colors);    //"red,blue,green,black"
        
        var instance2 = new SubType();
        alert(instance2.colors);    //"red,blue,green,black"
        
        
    </script>
</head>
<body>

</body>
</html>
  • QQ讨论群
  • 关注微信
    • 欢迎咨询
    • 欢迎加入QQ群 16506021
  • 公众号:源宝网络