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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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