<script type= "Text/javascript" >/*Requirements: You want to add the Getmax and Searchele methods to the array object. Functoin Array () {this.prototype = new Object (); This.getmax = function () {}} prototype note the details: 1. Prototype is a required property of a function (a written word is "reserved") (as long as it is a function, there must be a prototype attribute) 2. The value of prototype is an object 3. You can modify the value of the prototype property of a function arbitrarily. 4. An object automatically owns all the member properties and methods of the prototype. */Array.prototype.getMax=function(){ varMax = This[0]; for(varindex = 1; index< This. length; index++){ if( This[index]>max) {Max= This[index]; } } returnMax; } Array.prototype.searchEle=function(target) { for(vari = 0; i< This. length; i++){ if(target== This[i]) { returni; } } return-1; } //var arr = new Array (12,4,17,9); vararr = [12,4,17,9]; varMax =Arr.getmax (); varindex = Arr.searchele (9); document.write ("Maximum value:" + max+ "<br/>"); document.write ("Index value:" + index+ "<br/>");</script>
Prototype prototype properties