Search code examples
javascripthtmlphantomjscasperjs

Make createElement return function/true for fake tag


How can I make return "Function" for this request:

document.createElement("MY_FAKE_TAG").canThisRun

Now its return: undefined


Solution

  • You could extend the HTMLUnknownElement's prototype, but I really wonder if it's a good idea...

    HTMLUnknownElement.prototype.canThisRun = function(){console.log('hi')};
    
    document.createElement('foo').canThisRun();