Skip to content

Instantly share code, notes, and snippets.

@songxiaofeng1981
Created November 11, 2012 04:58
Show Gist options
  • Save songxiaofeng1981/4053772 to your computer and use it in GitHub Desktop.
Save songxiaofeng1981/4053772 to your computer and use it in GitHub Desktop.
homework:javascript
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