|  Topic awaiting preservation: A quextion I think about JS and variable scope (Page 1 of 1)  | |
|---|---|
| Bipolar (III) Inmate From: UK |  posted 08-03-2005 12:04 I'm just getting in to playing around with OO Javascript and having a problem, I think to do with scope, that I don't understand. code: function dataMunch(data) {
	this.compareNumbers = function(a, b) {
		return a - b;
	}
	this.aMax = function(arr) {
		arr.sort(this.compareNumbers);
		return arr[arr.length - 1];
	}
	this.aMin = function(arr) {
		arr.sort(this.compareNumbers);
		return arr[0];
	}
	this.munchData = function(data) {
		var nMax = this.aMax(data);
		var nMin = this.aMin(data);
	}
	alert(data);
	this.munchData(data);
	alert(data);
}
 | 
| Maniac (V) Inmate From:  |  posted 08-03-2005 12:48 The poster has demanded we remove all his contributions, less he takes legal action. | 
| Nervous Wreck (II) Inmate From:  |  posted 08-03-2005 13:30 (that bloody InI account..) I was saying: in js, variables are passed by reference. | 
| Bipolar (III) Inmate From: UK |  posted 08-03-2005 13:49 That makes things much clearer, thanks for the explanation _Mauro! | 
| Maniac (V) Inmate From:  |  posted 08-03-2005 13:53 The poster has demanded we remove all his contributions, less he takes legal action. | 
| Nervous Wreck (II) Inmate From:  |  posted 08-03-2005 13:54 You're welcome... sigh, stuck between a trailing underscore and an account that can't post. |