Advertisement
Guest User

Untitled

a guest
May 26th, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. <html>
  2. <head>
  3. <meta charset="utf-8" />
  4. <meta name="viewport" content="width=device-width, initial-scale=1" />
  5. <title>Brian Blessed demo</title>
  6. <style type="text/css">
  7. .out {
  8. font-weight: bold;
  9. }
  10. body {
  11. font: 14/20px sans-serif;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. Normal: <span class="out normal"></span><br />
  17. Patched: <span class="out patched"></span>
  18.  
  19. <script type="text/javascript">
  20. // This works with Babel
  21. class Name {
  22. constructor(first, last) {
  23. this.first = first;
  24. this.last = last;
  25. }
  26. getFull() {
  27. return this.first + ' ' + this.last;
  28. }
  29. }
  30.  
  31. (function() {
  32. var orig = Name.prototype.getFull;
  33. Object.defineProperty(Name.prototype, 'getFull', {
  34. get: function() {
  35. if (this.first === 'Brian' && this.last === 'Blessed') {
  36. return function() {
  37. return 'I AM BRIAN BLESSED!';
  38. }
  39. } else {
  40. return orig;
  41. }
  42. }
  43. });
  44. }());
  45.  
  46. document.addEventListener('DOMContentLoaded', function() {
  47. var john = new Name('John', 'Doe');
  48. var brian = new Name('Brian', 'Blessed');
  49. document.querySelector('.out.normal').innerHTML = john.getFull();
  50. // => John Doe
  51. document.querySelector('.out.patched').innerHTML = brian.getFull();
  52. // => I AM BRIAN BLESSED!
  53. });
  54. </script>
  55. </body>
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement