在聚合物中宣布一种功能

SKM*_*MTH 0 declaration function polymer

我试图在另一个中使用一个函数,但即使我事先声明它,聚合物说它不是.我不明白.任何线索?

Polymer({
is: 'x-foo',

//some other code here, including the properties....

computeRange: function (offset, limit, nodeRangeStart, nodeRangeEnd) {
  nodeRangeStart.innerText = offset;
  nodeRangeEnd.innerText = offset + limit;
},
prevPage: function () {
  this.offset = this.offset - this.limit;
  computeRange(this.offset, this.limit, this.$.usersListRangeStart, this.$.usersListRangeEnd);
  this.$.nextPage.removeAttribute('disabled');
  if (this.offset <= 0) {
    this.$.prevPage.setAttribute('disabled', true);
    this.$.prevPage.style.color = '#DDDDDD';
  };
}

});
Run Code Online (Sandbox Code Playgroud)

和控制台:

未捕获的ReferenceError:未定义computeRange

ton*_*y19 5

您试图将其称为computeRange()全局函数,但它实际上是构造函数对象的一部分.你需要使用this:

this.computeRange(...)
Run Code Online (Sandbox Code Playgroud)