Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // direct equivalent of PersonClass
- let PersonType2 = (function() {
- "use strict";
- const PersonType2 = function(name) {
- // make sure the function was called with new
- if (typeof new.target === "undefined") {
- throw new Error("Constructor must be called with new.");
- }
- this.name = name;
- }
- Object.defineProperty(PersonType2.prototype, "sayName", {
- value: function() {
- // make sure the method wasn't called with new
- if (typeof new.target !== "undefined") {
- throw new Error("Method cannot be called with new.");
- }
- console.log(this.name);
- },
- enumerable: false,
- writable: true,
- configurable: true
- });
- return PersonType2;
- }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement