The Magic Summoner of JS weapon spectrum: call/apply

Source: Internet
Author: User

PS: The following is the author when Climbing Lotus Mountain, some neurons in the brain flash sparks, and finally converted into a bunch of text fragments

When fortune, or not, should be when the singular doctor (Doctor Strange) was ancient one threw at the Everest summit was about to freeze to death, the feeling of desperation, he finally summoned the portal.

The world of magic, everywhere, as a Muggle, I learned JS, suddenly found that JS is incredibly part of the magic.

Call/apply, in fact, is an important embodiment of code reuse in JS.

These two goods are the method that the function comes with.

function, which is essentially a bunch of code statements packaged in one piece, can achieve some function.

The function in JS is also the object.

What is an object?

For example, I bought a bag of walnuts from the east of the dog, and the store was intimate with a walnut tongs.

Walnuts are both the data to be processed and the aim of processing walnuts is to eventually eat the meat inside.

Pliers, is the processing of data tools, (method), each call pliers once, you can crush one or more walnuts, unequal.

Seems a little far away,,,

JS author, the congenital to the function of the additional 2 methods: Call apply

They all accept two parameters, context and array of arguments.

Context, English is the context, this is a good word, worth chewing repeatedly.

It is the scene that the author of the PowerShell battle book is said to be scenario in English.

If you pass any context to call/apply, you can call the function to use in this scenario.

As if you bought an air conditioner, at this time, your context, or the scene, is your home

The air conditioning installation master, is the function

Send your home address time to master, then if the context to the teacher

Master, install the air conditioner. Leave.

-----------------------------------------------------------------

Suddenly understand why the ancient mage held the ceremony drawn Taoist charm finished, always shout on a voice: Lao Zi, Yuju Ruling.

Lam Ching Ying before catching the demon, also always put on the mouth to read the spell.

The Holy Warrior Star is always bilibala before it becomes a body.

Last night to see open the door, a costume designer was burst material said design before always sat, otherwise no inspiration.

So, before writing the JS code, should also be read what mantra?

"Burn It, fire bird." This is the first word that I want to jump out of my mind.

----------------------------------------------------------------------------

Some people say, the world article a big copy.

This word is used in the programming world, called code reuse.

In C + +, a class is a significant embodiment of code reuse.

JS6 no class before

With code reuse, we don't need to reinvent the wheel.

----------------------------------------------------------------------------

I thought about the function bindings and function currying

Implementation, the slice function is called multiple times.

  

The Magic Summoner of JS weapon spectrum: call/apply

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.