How does js overwrite the original method and overwrite the original method?

Source: Internet
Author: User

How does js overwrite the original method and overwrite the original method?

<Html> 

Objective: To improve the calling method.

If you have made an editor that provides some cursor exit events, you 'd better use this method, because when someone else uses your editor, you may need to use the event method provided by the editor to handle some things. Some of the events must be rewritten according to special requirements, it is necessary to provide event methods that are allowed to override the editor!


How can I use the js rewrite Method in actual projects? For example, I want to rewrite the js Rounding Method toFixed.

This toFixed function is a js native function and does not need to be added.
However, if you need to expand some native object functions, you can write them in a js file, and then introduce this js file to every page that needs to use it.
For example, you need to extend the Date object by adding format Date. prototype. format = function (strFormat ){}
Write this file in a separate js file, and then introduce this js file into every page.
<Script type = "text/javascript" src = "/js/date. format. js"> </script>

Will java method rewriting overwrite the original method?

No. If you use a subclass object to call, you call the overwritten method. If you use a parent class object to call the method, the method before rewriting is called, that is, the method that is not overwritten.

Related Article

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.