SDE2 Polyfill
Check if function is called with new keyword
Problem Description & Specifications
Testing
Implementation & Test Harness
Editable Monaco RunnerJavaScript Lab Sandbox
function A() {
// Using arguements.callee is highly discouraged and completely banned in JS in strict mode.
if ((this instanceof arguments.callee)) {
console.log("OK, new");
} else {
console.log("OK, function");
}
};
/*
Testing
*/
var Z = new A();
Z.lolol = A;
Z.lolol();Console Output
Click "Run Code" above to execute and view output...