讓polyfills爲document.register假設我寫了下面的Web組件或自定義元素:沒有在phantomjs工作
<!doctype html>
<html>
<head>
<script src="js/MutationObserver.js"></script>
<script src="js/CustomElements.js"></script>
<script>
var proto = Object.create(HTMLElement.prototype);
proto.createdCallback = function() { console.log('created');};
proto.enteredViewCallback = function() {};
document.register('x-foo', {prototype: proto});
document.createElement('x-foo');
</script>
</head>
<body>
</body>
</html>
(polyfill on github) 此作品在Chrome中。但是,當我嘗試在PhantomJS我碰到下面的錯誤運行此:
TypeError: instanceof called on an object with an invalid prototype property.
http://localhost/~me/js/CustomElements.js:18
http://localhost/~me/js/CustomElements.js:217 in instantiate
http://localhost/~me/js/CustomElements.js:333
http://localhost/~me/js/CustomElements.js:342 in createElement
...
如果要複製,這裏是我的phantomjs腳本
var page = require('webpage').create();
page.open('http://localhost/~me/test.html', function() {
phantom.exit();
});
我已經試過像
其他polyfills但實際上他們都沒有工作。任何想法如何解決這一問題 ?
可能的重複[爲什麼watch()和unwatch()在https://gist.github.com/384583的shim工作在phantomjs?](http://stackoverflow.com/questions/6998981 /爲什麼沒有這個shim-for-watch-and-unwatch-at-https-gist-github-com -384583) –