javascript - polymer 多重继承/组合

标签 javascript inheritance polymer web-component

polymer 网站says在 Polymer 中使用“扩展”属性不支持多重继承(或组合)。我希望一个元素由一个 Polymer 元素的一些方法和另一个 Polymer 元素的一些方法组成,以使其反射(reflect)应用程序逻辑。目前有什么方法可以在 Polymer 中实现吗? (就像使用 javascript mixins 那样做)

最佳答案

Polymer 现在支持 mixin:

var mixinObj = {
   foo: function() {
     /* ... */
   }
};

var mixinObj2 = {
   foo2: function() {
     /* ... */
   }
};


Polymer('my-component', Polymer.mixin({   // Platform.mixin for polymer version < 0.5
  bar: function() {

     /* ... */
     this.foo();   // all the functions in mixinObjs are now accessible through 'this'   
     this.foo2();   



  }


}, mixinObj, mixObj2);  // Platform.mixin accepts multiple mixin objects

更多信息 here

关于javascript - polymer 多重继承/组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23659670/

相关文章:

c++ - 如何在不取消定义类型的情况下为 C++ 中的类型编写 getter?

c# - 调用重写方法的祖父实现

javascript - 如何根据来自 json 的数据更改选择按钮颜色?

C++ : Calling a child method from parent instantiation

javascript - 在远程和本地连接上使用一个用户

dart - 使用Polymer.Dart无法找到 Assets

javascript - Polymer Core-Ajax文件上传

filter - polymer :三元运算符与 token 列表?

java - 带有 JavaScript 界面的 Webview

javascript - 关闭 `useState` 钩子(Hook)的结果会导致恼人的行为