I am trying to understand the behaviour of the new keyword and call in ES5. Let's suppose someone makes a mistake, has this code and runs it in a browser:
function Shape(colour) {
this.colour = colour;
}
function Circle(colour) {
Shape(this, colour);
}
var shape1 = Shape('blue'); // undefined
var shape2 = Circle('red'); // undefined
My question is, what happens?
window.colour // no points to window; shouldn't this point to 'red' now?
// window.colour now points to a circle object; why is there no colour property on the
//object but it rather points to a circle object?
new Circle('red');
I have read a few guides on this and new but haven't figured how they influence what happens.
Thanks for your help, Anagni