I come from the traditional web developer background where I can by no means claim to really know anything about Javascript, however I am trying.
I currently have wh
First of all, kudos on reading Javascript: The Good Parts it's a great book on the language.
To answer your question, the new
operator is required if you want to make use of prototypal inheritance. There is no other way to have an object "inherit" from another. That being said, you can copy properties from one object to another that would remove the need for the operator in some cases.
For example, a classical approach would use the following:
function MyClass() {};
MyClass.prototype.sayHello = function() {
alert('hello');
};
var o = new MyClass();
o.sayHello();
You can achieve relatively the same thing as follows:
function MyClass() {
return {
sayHello: function() {
alert('hello');
}
};
}
var o = MyClass();
o.sayHello();