Skip to content

Instantly share code, notes, and snippets.

@anhhh11
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anhhh11/f0ee534dfaac5e48fb95 to your computer and use it in GitHub Desktop.
Save anhhh11/f0ee534dfaac5e48fb95 to your computer and use it in GitHub Desktop.
var Pen = function(position){
this.position = position;
}
Pen.prototype.move = function(toPostition){
this.position = position
}
Pen.prototype.select = function(select){
this.select = select;
}
Pen.prototype.toJSON = function(){
return {
position: this.position,
select: this.select
}
}
var MagicPen = function(position,acc){
Pen.call(this,position);
this.acc = acc;
}
MagicPen.prototype = Object.create(Pen.prototype);
MagicPen.prototype.constructor = MagicPen;
MagicPen.prototype.toJSON = function(){
var obj = Pen.prototype.toJSON.call(this);
obj.acc = this.acc;
return obj;
}
var p = new Pen([1,1]);
p.select('todo');
p.toJSON();
var mg = new MagicPen([1,1],[1,2,3]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment