JS37---Function.prototype

Source: Internet
Author: User

    //Add a function named name to the prototype function, and the function body is FNFunction.prototype.method=function(NAME,FN) { This. prototype[name] = fn;// This        return  This; }        //The method of extending the array, the name of the new method, the function body, the parameter, the argument        if(!Array.prototype.forEach) {        //Array.prototype.forEach = function (fn,thisobj) {}                //This.fns.forEach (function (EL) {El (O);} ) function (EL) {El (O) is a functional argumentArray.method ("ForEach",function(fn,thisobj) {//Forrach is the function name, followed by the function declaration, and fn,thisobj is the formal parameter in the declaration.            varScope = Thisobj | |window;  for(vari = 0; I < This. length; i++) {Fn.call (scope, This[I],i, This); }        })    }    if(!Array.prototype.filter) {        //this.fns.filter (function (EL) {if (el! = XXX) {return el;}})Array.method ("Filter",function(fn,thisobj) {varScope = Thisobj | |window; varA = [];  for(vari = 0; i < Array.Length; i++) {                if(!fn.call (Scope, This[I],i, This) ){                    Continue; } A.push ( This[i])}//..........................            returnA; })    }
Window. DED = window. ded| | {};//You use yourself, you don't use empty objects.Ded.util = Ded.util | | {}    //observersDED.util.Observer =function(){         This. FNS = []    }    //extend himDED.util.Observer.prototype = {        //observedSubscribe:function(FN) { This. Fns.push (FN); },        //Cancel ObservationUnsubscribe:function(FN) { This. FNS = This. Fns.filter (function(EL) {if(El! =fn) {                    returnel; }            })        },        //array of the loop execution function being observedFire:function(o) { This. Fns.foreach (function(EL) {El (O); })        }    }
function (e) {          var e = e | | window.event;           var src = E.target | | e.srcelement;           Try {            e.preventdefault ();          }           Catch (ex) {            false;          }
functionF () {}varf =function() {} Function.prototype.method=function(NAME,FN) {alert (1); } f.method ();//1F.method ();//1 functionF () {}varf =function() {} Function.prototype.method=function(NAME,FN) { This. prototype[name] =fn; return  This; } f.method ("A",function() {alert ("a");});//1F.method ("B",function() {alert ("B");});//1    //F.A ();//F.A is not a functionF.prototype.a ();//a    //f.b ();//f.b is not a functionF.prototype.b ()//b    NewF (). b ();//b

The parameter is considered to be the value of the member variable passed in by the constructor. Function names are considered class names. This is considered a member property and a member method.

    functionAddcar () { This. Name = 11;  This. Begin =function(){//the Member Method property of the object can be obtained in bracketsAlert (1); }    }    NewAddcar (). Begin ();//1AlertNewAddcar () ["Begin"]);//this.begin = function () {alert (1);}Alerttypeof NewAddcar () ["Begin"]);//function    NewAddcar () ["Begin"] ();//1AlertNewAddcar () ["name"]);// One        varRR =NewAddcar (); rr["Age"] = 444; Alert (rr["Age"]);//444rr["fff"] =function() {Alert (777);} rr["FFF"] ();//777

JS37---Function.prototype

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.