React the transfer of function parameters

Source: Internet
Author: User



The transfer form of function parameters in JS is simple



Function Show (s) {



Console.log (s);



}



Show (' Hello '); It will output hello.



Bind is required for the transfer of function parameters in react JSX



Here is an example that can be used as a reference



http://www.jianshu.com/p/d745514e547b



Note that you have to define this and then use it, and use this directly to give an error, and the function defines



The Bind method is required to bind the parameter, the first parameter points to this, and the second argument starts with the parameter that the event function receives



Here's an example to illustrate everything.


var NoLink = React.createClass({
      show: function(dd){
       alert(dd)
      },

      render: function() {
        function show(rr){
        alert(rr)
        }
        var o = this;
        var message = [1,5,7,9,0];
        var sss = message.map(function(data){
        return(
        <input type="button" value={data} onClick={o.show.bind(data,data)} />
        )   
        })
          
        return(
         <div>
           {sss}
         </div>
         )        
      }
    });

      ReactDOM.render(
        <NoLink />,
        document.getElementById(‘example‘)
      );


React the transfer of function parameters


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.