1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| 'use strict'
function Animal(name) { if (!new.target) { throw new TypeError(`Class constructor ${this.constructor.name} cannot be invoked without 'new'`) } this.name = name }
Object.defineProperty(Animal.prototype, 'run', { value: function() { if (new.target) { throw new TypeError(`Animal.prototype.run cannot be invoked with 'new'`) } console.log(this.name + ' is running!') }, enumerable: false })
|