C ++, PHP, Javascript,..., lambda expression support

Source: Internet
Author: User
: This article mainly introduces C ++, PHP, Javascript,... and lambda expression Support. if you are interested in PHP tutorials, refer to it. Lambda

Lambda expressions, also known as Closure (Closure), are also called anonymous functions. Thanks to its strength, it is supported by almost all mainstream development languages. This article attempts to list the sample code of lambda expressions in most languages and will continue to be updated later.

PHP's support for lambda


  
  • External variables must be explicitly referenced, and the partition value and reference must be passed.

C ++'s support for lambda

#include  usingnamespacestd;int main(int argc, char** argv){ int i = 12; int j = 33; auto callable = [i, &j](){ cout << i << endl; cout << j << endl; }; callable(); i++; j++; callable();} 
  • You must display the referenced external variables, pass the partition value, and pass the reference.
  • Supported[=][&]To reference all external variables.

Javascript

《script》var i = 12;var j = 33;var callable = function(){ alert(i); alert(j);}callable();i++;j++;callable();
  • External variables are automatically available without reference.
  • All variables are passed by reference.

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.