寄生构造函数模式

2017-06-21 11:50:00
admin
原创
531
<!DOCTYPE html>
<html>
<head>
    <title>Hybrid Factory Pattern Example</title>
    <script type="text/javascript">
                    
        function Person(name, age, job){
            var o = new Object();
            o.name = name;
            o.age = age;
            o.job = job;
            o.sayName = function(){
                alert(this.name);
            };    
            return o;
        }
        
        var friend = new Person("Nicholas", 29, "Software Engineer");
        friend.sayName();  //"Nicholas"


        
    </script>
</head>
<body>

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