Prototype prototype properties

Source: Internet
Author: User

<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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.