对于复杂的元素,则是一个很好的做法,(几乎)总是有一个瓶盖内聚合物的定义,以保持所有这些只应修改内部私有变量和方法,而不是将它们连接到元素(例如,“这个”)?
就像下面:
<polymer-element name="animating-element">
<script>
(function() {
var privateObj = {};
privateObj.internalState = 0;
//private static method
privateObject.setupState = function(polymerObject) {
if(polymerObject.stateExposedToOutside == /* some conditions */) {
privateObject.internalState = 1;
}
}
Polymer('animating-element', {
stateExposedToOutside: 0,
ready: function() {
privateObj.setupState(this);
this.animate();
},
animate: function() {
}
});
})();
</script>
</polymer-element>