First of all, you should initialize the prototype at the same time as when you define the constructor, instead of redefining it every time you create a new instance.
// Define MyService Class
function MyService(someDependency) {
// ...
}
MyService.prototype.doSomething = function(){
// ...
}
After that, all that remains to go is to copy the parameters into instance variables explicitly
// Define MyService Class
function MyService(someDependency) {
this.someDependency = someDependency;
}
MyService.prototype.doSomething = function(){
return this.someDependency.doSomething();
}
All instance variables are piublic. If you want you can use a naming convention (like starting with an underscore) to mark "pseudo-private" variables.
If you want to use the function parameter directly instead of assigning instance variables you can have the methods be closures belonging to your object instead of a sharred function at the prototype. This lets you use variables from the constructor (and those variables are private!) but makes it harder to create subclasses.
function MyService(someDependency) {
this.doSomething = function(){
return someDependency.doSomething();
};
}
The version with closures can be slower than the prototype version but I wouldn't worry about i most of the time.