I believe this is the best way to achieve what you want.
var Thing = (function () {
function Thing(varOne) {
this.varOne = varOne;
}
Thing.prototype.saySomething = function () {
console.log(this.varOne);
};
return Thing;
})();
var app = new Thing("Cheese");
app.saySomething();
If you want to use objects and classes inside JavaScript, might I take the liberty to suggest TypeScript? It compiles into plain old javascript and can work with your existing javascript code.
Now some might suggest that this is a radical change. Its really not. Its just JavaScript with classes, and since its a superset of Javascript, it can make things infinitely easier. Furthermore, Typescript will be fully functional javascript when ECMAScript 6 is released, so why not use the to-be-released features today, and when it does come out, you can just change the type extension from typescript to javascript. If you just want to take a look at how it works, just look here.
Demo:
This is from a nodejs console.
> var Thing = (function () {
... function Thing(varOne) {
..... this.varOne = varOne;
..... }
... Thing.prototype.saySomething = function () {
..... console.log(this.varOne);
..... };
... return Thing;
... })();
undefined
> var app = new Thing("Cheese Cake");
undefined
> app.saySomething();
Cheese Cake
undefined
>
I generated the above js code using Typescript, this is what the Typescript looks like:
class Thing {
constructor( public varOne: string) {}
saySomething (): void {
console.log(this.varOne);
}
}
var app = new Thing("Cheese");
app.saySomething();
As you can see, the syntax is much cleaner. You can go to Typescript's official website to learn more.