Custom new operator

Run Settings
LanguageJavaScript
Language Version
Run Command
function isPrimitive(val) { return val !== Object(val); } function Person(firstName, lastName) { this.firstName = firstName; this.lastName = lastName; } function customNew(constructor, args) { const self = Object.create({}); const constructorValue = constructor.apply(self, args) || self; return isPrimitive(constructorValue) ? self : constructorValue; } const obj = customNew(Person, ['John', 'Doe']); console.log(obj);
Editor Settings
Theme
Key bindings
Full width
Lines