JavaScript 对象的3种基本构造法

//第一种构造法:new Object
var a = new Object();
a.x = 1, a.y = 2;

//第二种构造法:对象直接量(是不是就是json?)
var b = {x:1, y:2}
或
var b = {};
b.x = 1;
b.x = 2;

//第三种构造法:定义类型
function Point(x,y){
    this.x = x;
    this.y = y;
}
var p = new Point(1, 2);


以上摘自《JavaScript王者归来》

------------------------------------------------------------------

以下内容转自 http://www.cnblogs.com/huazai/archive/2009/05/14/1457145.html
 

//1.对象复制
   emptyObject = new Object();
   company.apply = function(o, c,)
    {

          if(o && c && typeof c == 'object')

         {
              for(var p in c)

             {
                o[p] = c[p];
             }
         }
         return o;
   };
   emptyObject = Ext.apply(emptyObject,company);




//2.对象复制(函数方式)
   var copyOO = new Function();
   copyOO.prototype = company;

   var newcopyOO = new copyOO();




你可能感兴趣的:(JavaScript,C++,c,C#,ext)