« 笑吾 | 首页 | 火柴 »

simaopig

个人主页: http://www.xiaoxiaozi.com

留言(2 条)

Javascript面向对象编程(三):非构造函数的继承 留言:

在《JavaScript 设计模式》一书中有介绍,只不过方法叫clone

同时,对于这种引用型数据的继承,书中介绍的是采用构造函数的方法返回

例如:


function clone(obj){
function F(){};
F.prototype = obj;
return new F;
}

var Chinese = {
    nation:'中国',
    createBirthPlaces : function(){
     return ['北京','上海','香港'];
   }
  };


var Doctor = clone(Chinese);
Doctor.career = '医生';
Doctor.birthPlaces = Chinese.createBirthPlaces();
//3
alert(Doctor.birthPlaces.length);
Doctor.birthPlaces.push('大连');
//4
alert(Doctor.birthPlaces.length);
//3
alert(Chinese.createBirthPlaces().length);

CSS使用技巧 留言:

先回后看,既然持续更新,当然要常期关注。

正要学CSS,这些技巧对我很实用。呵