I have the following constructor:
function Person(name, age) {
this.name = name;
this.age = age;
}
Now if I say:
var p = new Person("jon", 25);
It will create an instance of Person
but what if a user does the following:
var p = Person("jon", 25);
This will lead to name
and age
being defined on the window
object.
My question is, is there a way to prevent the user from calling Person
directly without new
and thus not allowing window
object to be augmented?