0

hi all
i have taken script from internet
but in this script i dont understand what does mean this.length. when we write

this.length

as what length we must understand it
here is code.

Array.prototype.max = function() {
var max = this[0];
var len = this.length;
for (var i = 1; i < len; i++) if (this[i] > max) max = this[i];
return max;
}
Array.prototype.min = function() {
var min = this[0];
var len = this.length;
for (var i = 1; i < len; i++) if (this[i] < min) min = this[i];
return min;
}
3
Contributors
3
Replies
6
Views
7 Years
Discussion Span
Last Post by Taywin
0

thanks but can u explain in this code

01.<script language="JavaScript">
02.<!--
03.today=new Date();
04.function initArray(){
05.  this.length=initArray.arguments.length
06.  for(var i=0;i<this.length;i++)
07.  this[i+1]=initArray.arguments[i] }
08.  var d=new initArray(
09.   "Sunday",
10.   "Monday",
11.   "Thuesday",
12.   "Wednesday",
13.   "Thursday",
14.   "Friday",
15.   "Saturday");
16.    document.write(
17.        "<font style='font-size:9pt;font-family:Verdana'> ",
18.               today.getYear(),"/",
19.           today.getMonth()+1,"/",
20.           today.getDate(),"/   ",
21.           d[today.getDay()+1],
22.    "</font>" ); 
23.//--></script>

what is here

this.length

Edited by azegurb: n/a

0
Array.prototype.max = function() {
  var max = this[0];
  var len = this.length;

'this' in this case is an array which is a local variable to 'Array' class object.

function initArray(){
  this.length=initArray.arguments.length

'this.length' in this case is the number of arguments passed to the function initArray.

You may need to read about 'this' keyword in JavaScript for more understanding.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.