sorry if answered somewhere (it is), i'm not quite sure how ask properly, failed @ searching :(
basically want this:
(a||b).prototype.c = function () { // }
basically , b objects. 1 or other exist, not both. don't know exist, need add method whichever 1 does.
now, know this:
if (typeof(a) == 'object') { a.prototype.c = c; } else if (typeof(b) == 'object') { b.prototype.c = c; } function c () { // }
but has problem of c having own namespace on global level, , don't want that. not want c have it's own namespace on global level @ point in time.
soo...obviously first bit of code above doesn't work. how go this? or not possible? please feel free close , point me in right direction if has been answered before...
i think solve problem:
(function() { var f = function() { //prototype function }; if(a) a.prototype.f = f; if(b) b.prototype.f = f; })();
Comments
Post a Comment