1

I am trying to create a very simple example with Google Polymer's platform.js, but I get the following error: Uncaught TypeError: Cannot read property '_polyfilled' of undefined

Here is what I am trying to do:

<current-date></current-date>

<script>
    document.registerElement('current-date', {
        prototype: {
            createdCallback: function() {
                this.innerHTML = new Date();
            }
        }
    });
</script>

http://jsbin.com/uwUxeYA/1/edit

Note that this code works perfectly in Google Canary without platform.js loaded. Am I using the polyfill incorrectly for other browsers (latest Chrome, Firefox, etc)?

4

1 回答 1

2

您没有正确创建原型。在这种形式下,它需要是:

document.registerElement('current-date', {
   prototype: Object.create(HTMLElement.prototype, {
     createdCallback: {
       value: function() {
         this.innerHTML = new Date();
        }
     }
   })
 });

IMO,更清晰的形式是:

var proto = Object.create(HTMLElement.prototype);
proto.createdCallback = function() {
  this.innerHTML = new Date();
};
document.registerElement('current-date', {prototype: proto});

工作演示:http: //jsbin.com/uwUxeYA/3/edit

于 2014-01-29T03:56:21.403 回答