javascript 对象创建几种方式

2016-01-13 0 844
javascript 对象创建几种方式
/**Object*/
 var obj=new Object;
 obj.name="me";
 obj.action=function(){alert("method");};
 /**构造方法*/
 function construction(){
     this.name="me";
     this.action=function(){alert("method");};
 };
 var obj=new construction();
 /**构造方法call*/
function construction(){
    this.name="me";
    this.action=function(){alert("method");};
  };
 var obj={}; 
 construction.call(obj); 
 /**匿名构造方法call*/
 var obj={};
 (function(){
     this.name="me";
    this.action=function(){alert("method");}; 
 }).call(obj);
 /**单实例构造方法,属性共享*/
 var obj = function () {};
 obj.prototype.name = 'me';
 obj.prototype.action = function () {
     alert("method");
 }
 var obj1=new obj();

遇见资源网 js/jquery javascript 对象创建几种方式 http://www.ox520.com/11322.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务