Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript回调中的作用域_Javascript_Polymer_Polymer 1.0 - Fatal编程技术网

Javascript回调中的作用域

Javascript回调中的作用域,javascript,polymer,polymer-1.0,Javascript,Polymer,Polymer 1.0,我希望在第二个控制台.log(this.items)上看到数组[“foo”,“bar”]。但是,我得到了未定义的 如何获得[“foo”,“bar”]而不是未定义的 http://jsbin.com/hodegimohu/edit?html,控制台,输出 <!doctype html> <head> <meta charset="utf-8"> <base href="https://polygit.org/components/">

我希望在第二个
控制台.log(this.items)
上看到数组
[“foo”,“bar”]
。但是,我得到了未定义的

如何获得
[“foo”,“bar”]
而不是
未定义的

http://jsbin.com/hodegimohu/edit?html,控制台,输出
<!doctype html>
<head>
  <meta charset="utf-8">
  <base href="https://polygit.org/components/">
  <script src="webcomponentsjs/webcomponents-lite.min.js"></script>
  <link href="polymer/polymer.html" rel="import">

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>

</head>
<body>

<dom-module id="x-element">
<script>
  (function(){
    Polymer({
      is: 'x-element',
      properties: {
        items: {
          type: Array,
          value: ['foo','bar']
        },
      },
      ready: function(){
        console.log(this.items) // ["foo", "bar"]
        google.charts.load('current', {
          'packages': ['geochart']
        });
        google.charts.setOnLoadCallback(this._drawRegionsMap);
      },
      _drawRegionsMap: function() {
        console.log(this.items); // undefined
      },
    });
  })();
</script>
</dom-module>
<x-element></x-element>
</body>

(功能(){
聚合物({
是‘x元素’,
特性:{
项目:{
类型:数组,
值:['foo','bar']
},
},
就绪:函数(){
console.log(this.items)/[“foo”,“bar”]
google.charts.load('current'{
“包”:[“地球艺术”]
});
google.charts.setOnLoadCallback(this.\u DrawRegionMap);
},
_DrawRegionMap:function(){
console.log(this.items);//未定义
},
});
})();

只需使用
.bind

google.charts.setOnLoadCallback(this._drawRegionsMap.bind(this));

只需适当地处理回调(不基于聚合物)。

只需使用
.bind

google.charts.setOnLoadCallback(this._drawRegionsMap.bind(this));
只不过是适当地处理回调(不基于聚合物)