如何在聚合物中存在私有的非靜態變量?聚合物中的私有非靜態變量?
在:
<polymer-element name="component-one">
<script>
Polymer('component-one', {
internalState = 1,
ready() {
this.anotherInternalState = 1;
}
/* more variables and functions */
});
</script>
</polymer-element>
internalState和anotherInernalState都暴露於外部(例如,通過類似訪問:
document.querySelector('component-one').internalState
(從外部改變internalState時,這可能是不希望使組件不穩定。 )
其中:
<polymer-element name="component-two">
<script>
(function() {
var internalState = 1;
Polymer('component-two', {
/* some variables and functions */
});
})();
</script>
</polymer-element>
internalState從外部隱藏,但它是靜態的並在組件的所有實例之間共享。
有沒有辦法在聚合物對象內部有一個私有的非靜態變量?
感謝Scott,我只是看着FB React,看到React有一個屬於該組件的狀態屬性。是不是有用到足以加入聚合物的東西? (對我的愚見來說,它是:) – sepans
鏈接:http://facebook.github.io/react/docs/tutorial.html#reactive-state – sepans
希望這個功能是建議在0.8和1.0 API – andrsnn