將當前對象傳遞給回調函數的最佳方式是什麼?將當前聚合物對象(this)傳遞給回調函數
我一直在使用類似:
var that = this;
例如:
<link rel="import" href="/bower_components/polymer/polymer.html">
<polymer-element name="stackx-example">
<template>
<div id="container">{{innards}}</div>
</template>
<script>
Polymer('stackx-example', {
ready: function() {
var jax = new XMLHttpRequest();
jax.open('GET', '/jaxson/testing/', true);
jax.send();
var that = this;
jax.onreadystatechange = function(){
if (jax.readyState == 4 && jax.status == 200) {
that.innards = jax.responseText;
}
}
},
innards: '..missing'
});
</script>
</polymer-element>
我一直在做同樣的事情。 IDK,如果它被認爲是正確的 – 2014-12-04 18:18:57