A
Asen Bozhilov
I want to create design which augment native objects with some
additions from ES5 and user defined properties. I don't want touch
explicit build in prototype objects. I want to provide this
possibility to user of my code and possibility to create own additions
which augment native objects.
var Lib = {
additions : {
Array : {}
},
importAdditions : function(add_prop, o)
{
augment(o, Lib.additions[add_prop]);
return o;
}
};
var arr_additions = Lib.additions.Array;
if (typeof Array.prototype.forEach != 'function')
{
arr_additions.forEach = function(){
//do forEach
};
}
/* augment instance object */
Lib.importAdditions('Array', []);
/* augment build in `object' referred from `Array.prototype` */
Lib.importAdditions('Array', Array.prototype);
Of course i know all disadvantages of this pattern, and if i port in
real project, I'll be write documentation.
I am wonder, what is opinion on members of c.l.js about this pattern
and similar?
Thanks in advance.
additions from ES5 and user defined properties. I don't want touch
explicit build in prototype objects. I want to provide this
possibility to user of my code and possibility to create own additions
which augment native objects.
var Lib = {
additions : {
Array : {}
},
importAdditions : function(add_prop, o)
{
augment(o, Lib.additions[add_prop]);
return o;
}
};
var arr_additions = Lib.additions.Array;
if (typeof Array.prototype.forEach != 'function')
{
arr_additions.forEach = function(){
//do forEach
};
}
/* augment instance object */
Lib.importAdditions('Array', []);
/* augment build in `object' referred from `Array.prototype` */
Lib.importAdditions('Array', Array.prototype);
Of course i know all disadvantages of this pattern, and if i port in
real project, I'll be write documentation.
I am wonder, what is opinion on members of c.l.js about this pattern
and similar?
Thanks in advance.