JavaScript this attribute, static method, and instance method, prototype

Source: Internet
Author: User
Tags instance method

<script type= "Text/javascript" >functionlogs (str) {document.write (str+ "<br/>")    }    //chained calls can be implemented using the "this pointer to function caller" feature. Most of the jQuery is chained calls    varOname ={name:"AA", Age:999    }; Window.name= "I am Window"; functionShowName () {logs ( This. Name); } oname.show=ShowName; Window.show=ShowName; Oname.show (); /*AA*/window.show ();/*I am Window*/Oname.showname=function() {logs ( This. Name); return  This;//The "This" in JavaScript is a function context that is not determined at the time of the declaration, but is determined at the time of the call.    }; Oname.showage=function() {logs ( This. Age); return  This; } oname.showname (). Showage (); //AA 999    //method Static method instance method The same attribute instance method in Java must declare an object before the object can invoke the    functionStaticclass () {};//declaration of a classStaticclass.staticmethod =function() {logs ("Static Method")    }; //Create a static methodStaticClass.prototype.instanceMethod =function() {logs ("Instance method")    } //Create an instance methodStaticclass.staticmethod ();//static Method    //Staticclass.instancemethod (); Statement error, unable to run    NewStaticclass (). Instancemethod ();//must be instantiated to invoke instance method    //The essence of the dynamic prototyping approach is to use the prototype Declaration instance method, which declares the instance properties    functionCar () { This. color = "None";//examples are        if(typeofcar._initialized = = "undefined") {Car.prototype.showCar=function() {//instance MethodLogs This. color); }} car._initialized=true;//static properties? Instance properties?} logs (Car.color); //undefinedLogs (car._initialized);//undefined?    varCar =NewCar (); Logs (Car.color); //NoneLogs (car._initialized);//true?Logs (car._initialized);//undefined?Car.showcar ();//None        /*car._initialized is the static property 1 error, because your car._initialized property assignment is inside the class, JS is to explain where to perform where, because of this, when there is an instance of Car, static properties _initiali Zed is assigned a value, so 2 is true, and 3 does not output because it is a static property, not an instance property. */</script>

ref:http://sblig.iteye.com/blog/1542896

JavaScript this attribute, static method, and instance method, 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.