I need a way to add new methods to the existing one on some DOM elements (in my case, canvas). I want to do something like this :
var c= document.getElementById('myCanvas');
c.foo = function(){
console.log('foo' + this.id);
}
c.bar = function(){
console.log('bar' + this.id);
}
Because it will be used for several canvas elements I don't want to write this code each time.
I could use a method that add this methods to all of my elements, but I was wondering if there is a way to do this with OOP (inheritance ?).
Could I do something like this ?
var extendedCanvas = function(){
this.foo = function(){
console.log('foo' + this.id);
};
this.bar = function(){
console.log('bar' + this.id);
}
}
var c= document.getElementById('myCanvas');
c.prototype = new extendedCanvas();
c.foo();