I built a parser and I would like to 'extend' the Array class in order to use the same functions but have not been successful with:
Array.prototype = new Parser()
I would like to create a function that would reuse the shift from the array without me having to add:
function() { return this.list.shift() }
Also I've been having some problems with the this
identity so:
How can i effectively prototype Array or from Array to reuse code ?
function Parser() {
this.get_info_colors = function() {
return {
'id': self.shift(),
'name': self.shift(),
'colors': self.get_colors()
}
}
this.get_info_grad = function() {
return {
'id': self.shift(),
'name': (self.shift() + '_grad'),
'grad': self.shift()
}
}
this.get_colors = function() {
this.shift();
var result = [],
element;
while(element != ']') {
element = this.shift();
result.push();
}
return element;
}
this.builder = function(factory) {
this.shift();
var result = [],
element;
while(element != ']') {
result.push(factory());
}
return result;
}
this.color_builder = function() {
return this.builder(this.get_info_colors);
}
this.grad_builder = function() {
return this.builder(this.get_info_grad);
}
}
Thanks in advance.