JavaScript Object-oriented learning five (JS native reference type Array, object, string, etc.) Introduction to prototype objects

Source: Internet
Author: User

1. The importance of prototype mode is not only in the creation of custom types, but even all native reference types (obejct, Array, String, and so on) define methods and properties on the constructor's prototype. The following code can prove:

    Alert (typeof// output: function    alert (typeof// output: function

Through the prototype of the native object, you can not only get references to all the default methods, but also define new methods. You can modify the prototype of a native object just as you would modify the prototype of your own definition object, so you can add the method we need at any time to the native object. The code is as follows:

    string.prototype.startswith=function(TXT) {      returnthis. indexOf (TXT) ==0 ;    }     var msg= "Hello world!" ;    Alert (Msg.startswith (// output: True, stating that MSG starts with a "Hello" word

JavaScript Object-oriented learning five (JS native reference type Array, object, string, etc.) Introduction to prototype objects

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.