Open k-j-kim opened 7 years ago
Hm, maybe we should use the cloneNode
method when dealing with document nodes?
Can confirm that this fails in Safari 10.1:
Object.create(Object.getPrototypeOf(document.createElement('div'))).align = 'foo'
but this does not:
document.createElement('div').cloneNode().align = 'foo'
We'd want to copy over properties afterwards. I don't think we can clone event listeners.
btw, Object.create( Object.getPrototypeOf(document.createElement('div'))).align = 'foo'
will fail in Chrome (Version 57.0.2987.133 (64-bit)) as well, although with a different error message:
Uncaught TypeError: Illegal invocation
.
Agree that with document nodes, cloneNode
should be used.
Any updates on this?
There are more cases where Object.create(Object.getPrototypeOf(...))
fails. For example: const url = clone(new URL('http://example.com'))
throws the same Uncaught TypeError: Illegal invocation
in chrome and TypeError: 'set href' called on an object that does not implement interface URL.
in Firefox
When copying a DOM object, following line fails:
child[i] = _clone(parent[i], depth - 1);
https://github.com/pvorb/clone/blob/e3f252d1eb24f4e269337098295604e266719d4d/clone.js#L156TypeError: The HTMLDivElement.align setter can only be used on instances of HTMLDivElement
It seems like calling
Object.getPrototypeOf
on a DOM element givesHTMLDivElementPrototype
which has a slightly different behavior thanHtmlDivElement
.Reproducible in Safari Version 10.0 (10602.1.50.0.10)