calling-without-new.js
✓ Published0🌍 Public
Aalessioalex
Last edited Nov 22, 2014
Created on Nov 22, 2014
This example shows a JavaScript workaround for calling a constructor function without the `new` keyword. It defines a `Student` constructor that checks `this instanceof Student` and, if false, automatically returns a new instance via `new Student(...)`. The code then invokes `Student('John', 18, 'MIT')` without `new`, demonstrating how the guard ensures proper instantiation. It uses plain JavaScript constructor logic, with a commented-out call to `Person.call` indicating an intended inheritance pattern. The example prints a result via `junior2.getInfoCard()`, though the method itself is not defined in the visible snippet.
AI-generated description