There's a little bit of confusion about what you're asking. You are currently not using the prototype (couldn't tell from your question whether you realized that or not) for your methods or properties and that technique works just fine if you create an object from the function with new like this:
function Gadget(name, color) {
this.name = name;
this.color = color;
this.whatAreYou = function(){
return 'I am a ' + this.color + ' ' + this.name;
}
}
var x = new Gadget("Faucet", "red");
x.whatAreYou(); // returns 'I am a red Faucet'
Working demo: http://jsfiddle.net/jfriend00/wPP7N/
When the new operator is used, it creates a new object and calls the function with this assigned to the new object. Any properties you add to the object that this points to in the constructor then become properties of the new object.
In fact, properties with a dynamic value like name and color in your example are often assigned like this in the constructor as there is little advantage to using the prototype for them because they get assigned a dynamic value. There is a performance advantage to assigning methods such as your whatAreYou method using the prototype because less code has to run at constructor time - though the difference is not huge.
To compare and contrast, code using the prototype to define the method would look like this:
function Gadget(name, color) {
this.name = name;
this.color = color;
}
Gadget.prototype.whatAreYou = function(){
return 'I am a ' + this.color + ' ' + this.name;
}
var x = new Gadget("Faucet", "red");
x.whatAreYou(); // returns 'I am a red Faucet'
If you just call the function plainly like:
Gadget();
Then, there is no new object created and this will either point to the global object or will be undefined (in Strict mode) so the properties would not be on a Gadget-specific object.
newwhen you instantiate that "class" orthiswill be bound to the outermost scope.new Gadget().