简体   繁体   中英

"Illegal invocation" error for call to member of newly-created Web components object

When I try to run the clear function in the following code snippet in Chrome, I get an Uncaught TypeError: Illegal invocation error.

I'm creating a web component with some functions for a text input. This is my first method but I keep getting that error and I have no clue what it could be.

var XEditProto = Object.create(HTMLInputElement.prototype);

XEditProto.clear = function() {
    this.value = '';
    return "Erased";
}

var Edit = document.registerElement('x-edit', {
    prototype: XEditProto,
    extends: 'input'
});
document.body.appendChild(new Edit());
var XEditProto = Object.create(HTMLInputElement.prototype);

XEditProto.clear = function() {
    this.value = '';
    return "Erased";
}

var Edit = document.registerElement('x-edit', {
    prototype: XEditProto,
    extends: 'input'
});
var x = document.body.appendChild(new Edit());

...

x.clear();

Works as expected

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM