First, you need to assign a function to an object. Right now you're invoking a function, not assigning it.
If you want to invoke setBoxDimensions with static arguments, then you assign an anonymous function to this.setMedium/Large and have that invoke setBoxDimensions.
But it also seems that you don't want setBoxDimensions to be exposed. In that case, you need to invoke it via the .call() method, which lets you set its this value.
function Box() {
// use the setBoxDimensions since we have it.
this.setSmall = function (){
setBoxDimensions.call(this, 14,10,6);
}
this.setSmall(); // to initialize instead of repeating the code above
// assign anonymous functions that invoke `setBoxDimensions`
this.setMedium = function() {
// call setBoxDimensions, and set its `this` to the current `this`
setBoxDimensions.call(this, 16,14,6);
}
this.setLarge = function() {
// call setBoxDimensions, and set its `this` to the current `this`
setBoxDimensions.call(this, 24,14,6);
}
this.initBoxDimensions = this.setSmall;
function setBoxDimensions(length, width, height){
this.length = length;
this.width = width;
this.height = height;
}
}
var newBox = new Box();
newBox.setSmall();
console.log(newBox);
If you wanted setBoxDimensions to be a publicly exposed method, then you can set it on this. Also, it's probably a good idea to take advantage of prototypal inheritance here.:
function Box() {
this.setSmall();
}
Box.prototype.setSmall = function (){
this.setBoxDimensions(14,10,6);
}
Box.prototype.setMedium = function() {
this.setBoxDimensions(16,14,6);
}
Box.prototype.setLarge = function() {
this.setBoxDimensions(24,14,6);
}
Box.prototype.initBoxDimensions = Box.prototype.setSmall;
Box.prototype.setBoxDimensions = function(length, width, height){
this.length = length;
this.width = width;
this.height = height;
}
var newBox = new Box();
newBox.setSmall();
console.log(newBox);
this.setMedium = function() { setBoxDimensions.call(this, 16, 14, 16); };