Created
November 11, 2012 04:58
-
-
Save songxiaofeng1981/4053772 to your computer and use it in GitHub Desktop.
homework:javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it('inherts',function () { | |
var Model = new Class( | |
{ | |
initialize:function (name) { | |
this.name = name; | |
}, | |
save:function () { | |
return "my name is "+this.name; | |
} | |
}); | |
var todo = new Model('jobs'); | |
assert("my name is jobs",todo.save()); | |
}) | |
// 类的模拟 | |
// 构造函数 | |
// 类继承 todo | |
// 多态 todo | |
//有问题的方法 | |
var Class = function () { | |
var klass = function () { | |
this.initialize.apply(this,arguments) //this中没有init,找原型 | |
}; | |
klass.fn = klass.prototype;//todo 污染 | |
return klass; | |
}; | |
var Model = new Class(); //定义类 | |
Model.fn.initialize = function () { | |
this.save = function () {}; | |
}; | |
var View = new Class(); | |
View.fn.intiialize = function () { | |
this.render = function () {}; | |
}; | |
var todo = new Model(); | |
console.log(typeof todo.save); | |
// console.log(typeof view.render); | |
// var view = new View(); | |
// console.log(typeof view.save); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment