码迷,mamicode.com
首页 > 编程语言 > 详细

javascript不用new关键字创建对象示例

时间:2016-01-29 11:39:40      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:

<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>无标题文档</title>
    <script language="JavaScript">
<!--
 
        function P(name) {
            if (!(this instanceof P))
                return new P(name);
            //return new P(arguments);
            //var _this = this === window ? {} : this;
            var _this = this;
            _this.name = name;
        }
 
        P.prototype.show = function () {
            alert(this.name + ‘_‘ + this.T);
        }
 
        P.prototype.T = ‘6‘
 
        var a = new P(‘a‘);
        a.show();
        var b = P(‘b‘);
        b.show();
 
        a.show();
 
 
//-->
    </script>
</head>
 
<body>
</body>
</html>

 

javascript不用new关键字创建对象示例

标签:

原文地址:http://www.cnblogs.com/Sandheart/p/5168065.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!