Advertisement
Guest User

Untitled

a guest
May 26th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. // direct equivalent of PersonClass
  2. let PersonType2 = (function() {
  3.  
  4. "use strict";
  5.  
  6. const PersonType2 = function(name) {
  7.  
  8. // make sure the function was called with new
  9. if (typeof new.target === "undefined") {
  10. throw new Error("Constructor must be called with new.");
  11. }
  12.  
  13. this.name = name;
  14. }
  15.  
  16. Object.defineProperty(PersonType2.prototype, "sayName", {
  17. value: function() {
  18.  
  19. // make sure the method wasn't called with new
  20. if (typeof new.target !== "undefined") {
  21. throw new Error("Method cannot be called with new.");
  22. }
  23.  
  24. console.log(this.name);
  25. },
  26. enumerable: false,
  27. writable: true,
  28. configurable: true
  29. });
  30.  
  31. return PersonType2;
  32. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement