check for HTML* type on object
Posted: Mon Feb 15, 2010 4:31 pm
hey i am running to a wall here trying to figure out an objects type. i made a little addChildren function which is great but what if i accidently invoke it on an object that is not an HTMLElement?
oh uhhhh.. this seems kind of silly but heres what i did:
oh uhhhh.. this seems kind of silly but heres what i did:
Code: Select all
Object.prototype.appendChildren = function ()
{
if (arguments.length == 0)
throw "appendChildren() requires at least one parameter!";
// the magic
if (!(/HTML/.test(this)))
throw "appendChildren must be called from an HTML* object.";
for (var i = 0; i < arguments.length; i++)
this.appendChild(arguments[i]);
}