简体   繁体   中英

Javascript using different configurations for different outputs

Hi being a complete and utter idiot at the moment, where I have staring at this stuff for hours and now have no clue what I am doing.

Basically in one which I will name here as product.js I have Global Variables fixed

var AREA_MAX_MAXX = 1000;
var AREA_MAX_MINX = 60;

these are being then being used within another js which I will call library.js with the following:

this.area_max_maxx = AREA_MAX_MAXX;
this.area_max_miny = AREA_MAX_MINX;

this.calcPos = function() {
  var areaMaxWidth = this.area_max_maxx - this.area_max_minx;

What I want to do is remove the Global Variables and instead have it set up with arrays, so that whatever the array is the values will be set for area_max_maxx

Can anyone help me out there??? Am I making sense?

You mean like this?

this.minAndMax = [60, 1000];
this.calcPos = function() {
  var areaMaxWidth = this.minAndMax[1] - this.minAndMax[0];
}

I would recommend instead using an object:

this.areaParameters = {min: 60, max: 1000}
this.calcPos = function() {
  var areaMaxWidth = this.areaParameters.max - this.areaParameters.min;
}

Later, you can just say this.areaParameters.max = 3000 and next time calcPos gets called it will use the new value.

This is not possible. You are passing a value not a reference here:

this.area_max_maxx = AREA_MAX_MAXX;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM