Skip to content

Instantly share code, notes, and snippets.

@flyingzl
Created May 16, 2013 07:38
Show Gist options
  • Save flyingzl/5590048 to your computer and use it in GitHub Desktop.
Save flyingzl/5590048 to your computer and use it in GitHub Desktop.
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
if( !Object.create){
Object.create = function( o ){
function actor() {}
actor.prototype = o;
return new actor();
}
}
var Model = {
prototype: {
init: function() {
console.log( "model....")
}
},
create: function() {
var obj = Object.create( this );
obj.prototype = obj.fn = Object.create( this.prototype );
obj.parent = this;
return obj;
},
init: function() {
var instance = Object.create( this.prototype ) ;
instance.parent = this;
instance.init.apply( instance, arguments );
return instance;
},
extend: function( o ){
$.extend( this, o);
},
include: function( o ) {
$.extend( this.prototype, o );
}
}
Model.extend({
find: function() {
console.log('find')
}
});
Model.include({
init: function() {
console.log('instance');
}
});
var User = Model.create();
User.include({
say: function(){
console.log('user say....');
},
init: function() {
console.log(' user init...')
}
});
var user = User.init(),
user2 = User.init();
var Asset = Model.create(),
asset = Asset.init();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment