Guest User

Untitled

a guest
Oct 22nd, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. class NameTag extends HTMLElement {
  2.  
  3. // Assign a private variable to store the name property
  4. constructor() {
  5. super();
  6. this._name = '';
  7. }
  8.  
  9. // Static method that returns an array with the name of
  10. // all the properties that should be observed
  11. static get observedAttributes() { return ["name"]; }
  12.  
  13. // A lifecycle call back that gets invoked every time
  14. // a property in the observation list changes. This method
  15. // leaves room to do some dirty checking
  16. attributeChangedCallback(name, oldValue, newValue) {
  17. if (newValue !== oldValue && name === 'name') {
  18. this.name = newValue;
  19. }
  20. }
  21.  
  22. // ES6 setter method for the name property which gets
  23. // called when the value for `name` is assigned
  24. set name(val) {
  25. this._name = val;
  26. this.innerHTML = this._name;
  27. }
  28.  
  29. // ES6 getter method for the name property which gets
  30. // called when the value for `name` is read
  31. get name() {
  32. return this._name;
  33. }
  34. }
Add Comment
Please, Sign In to add comment