Skip to content

Instantly share code, notes, and snippets.

@constantology
Last active December 12, 2015 08:48
Show Gist options
  • Save constantology/4746471 to your computer and use it in GitHub Desktop.
Save constantology/4746471 to your computer and use it in GitHub Desktop.
function Person(/* whatever args your gonna have*/) {
this.onSave_ = this.onSave.bind( this );
this.onSetAge_ = this.onSetAge.bind( this );
}
Person.prototype.save = function() {
this.database.insert( this.properties, this.onSave_ );
};
Person.prototype.setAge = function( newAge ) {
this.constructor.validate( "age", this, newAge, this.onSetAge_ );
};
Person.prototype.onSave = function( err, result ) {
if ( err )
throw err;
this.properties = result;
};
Person.prototype.onSetAge = function( err, result ) {
if ( err )
throw err;
this.age = result;
};
;!function( Super ) {
function ExquisitePerson() {
Super.apply( this, arguments );
}
ExquisitePerson.validate = Super.validate;
ExquisitePerson.prototype = Object.create( Super.prototype );
ExquisitePerson.prototype.setAge = function( newAge ) {
newAge *= .67; // equisite type persons age much more slowly than normal sucker type persons
Super.prototype.setAge.apply( this, arguments );
};
ExquisitePerson.prototype.onSave = function( err, result ) {
Super.prototype.onSave.apply( this, arguments );
// do something exquisite here to disriminate against normal sucker type persons in favour of equisite type persons
};
}( Person );
@barraponto
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment