cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <!-- define element -->
<dom-module id="custom-element">
  <template>
    <h1>{{title}}</h1>
    <ul>
      <li>{{first}}</li>
      <li>{{second}}</li>
      <li>{{third}}</li>
    </ul>
  </template>
  <!-- initialize element -->
  <script>
    HTMLImports.whenReady(function(){
      Polymer(CustomElement); 
    });
  </script>
</dom-module>

<!-- add element to page -->
<custom-element title="ES6 Polymer Behaviors - Extending Multiple Behaviors"></custom-element>
            
          
!
            
              'use strict';

(() => {
  // define a behavior
  const FirstBehavior = {
    properties: {
      first: {
        type: String,
        value: 'First Behavior'
      }
    }
  };
  // define another behavior
  const SecondBehavior = {
    properties: {
      second: {
        type: String,
        value: 'Second Behavior'
      }
    }
  };
  // define another behavior
  const ThirdBehavior = {
    properties: {
      third: {
        type: String,
        value: 'Third Behavior'
      }
    }
  }; 
  // define a behavior which bundles the related behaviors ...
  const FourthBehavior = [
    FirstBehavior, 
    SecondBehavior, 
    ThirdBehavior
  ];
  // add the behavior to a namespace ...
  const ns = (window.SomeNamespace = window.SomeNamespace || {
    'FirstBehavior'  : FirstBehavior,
    'SecondBehavior' : SecondBehavior,
    'ThirdBehavior'  : ThirdBehavior,
    'FourthBehavior' : FourthBehavior
  });
})();

// define element class ...
class CustomElement {
  beforeRegister(){
    this.is = 'custom-element';
    this.properties = {
      title: {
        type: String
      }
    };
  }
  // implement behaviors getter, returning an array of behaviors which are to be 
  // extended via this._behaviors, or, assigning and returning the array of behaviors 
  // to be extended should this._behaviors be undefined ...
  get behaviors() {
    const ns = window.SomeNamespace || {};
    return this._behaviors || (this._behaviors = [
      ns.FirstBehavior,
      ns.SecondBehavior,
      ns.ThirdBehavior
    ]);
  }
  // implement corresponding setter ...
  set behaviors(val) {
    this._behaviors = val;
  }
}
            
          
!
999px
Loading ..................

Console