将当前对象传递给回调函数的最佳方式是什么?将当前聚合物对象(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