JavaScript call/apply

Source: Internet
Author: User

* Implement function Callit, after the call to meet the following conditions
1. The result returned is the result after the call to FN
2, the call parameter of FN is callit all parameters after the first parameter

function Callit (FN) {    return fn.apply (This, [].slice.call (arguments, 1));} TESTVAR fn = function (A, B, c) {return a+b+c;} Callit (FN, 1, 2, 3);   6

  

* Implement function Partialusingarguments, after the call satisfies the following conditions:
1. Returns a function result
2. After calling result, the returned result is consistent with the result of calling the function fn
3, the call parameter of FN is partialusingarguments all parameters after the first parameter and the call parameter of result

function Partialusingarguments (FN) {    var args = [].slice.call (arguments, 1);    return function () {    //[].slice.call (arguments) = = Convert arguments pseudo-array to array    return fn.apply (This, Args.concat ([] . Slice.call (arguments))    }}

  

JavaScript call/apply

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.