美文网首页Web前端
react中三种函数调用方法总结

react中三种函数调用方法总结

作者: w晚风 | 来源:发表于2021-03-22 17:02 被阅读0次

方式一:内联调用法


import React, { Component } from 'react';

class func extends Component{
    constructor(porps){
        super(props);
    }
    funcOne(){
        console.log('内联调用法')
    }
    render(){
        return (
            <button onClick={this.funcOne.bind(this)}></button>
        )
    }
}

方式二:配置中调用法


import React, { Component } from 'react';

class func extends Component{
    constructor(porps){
        super(props);
        this.funcTwo = this.funcTwo.bind(this)
    }
    funcTwo(){
        console.log('配置中调用法')
    }
    render(){
        return (
            <button onClick={this.funcTwo}></button>
        )
    }
}

方式三:箭头函数调用法(最推荐)


import React, { Component } from 'react';

class func extends Component{
    constructor(porps){
        super(props);
    }
    funcThree:() => {
        console.log('箭头函数调用法')
    }
    render(){
        return (
            <button onClick={this.funcThree}></button>
        )
    }
}

本文借鉴于:https://www.jianshu.com/p/601109471bbb

相关文章

  • react中三种函数调用方法总结

    隔壁大神刚刚跟我说了一个知识点,总结如下,以备后查! 方式一:内联调用法 方式二:配置中调用法 方式三:箭头函数调...

  • react中三种函数调用方法总结

    方式一:内联调用法 方式二:配置中调用法 方式三:箭头函数调用法(最推荐) 本文借鉴于:https://www.j...

  • JS函数的定义与调用方法

    JS函数调用的四种方法:方法调用模式,函数调用模式,构造器调用模式,apply,call调用模式 1.方法调用模式...

  • js apply、call、bind

    apply是函数的一种调用模式。函数调用模式有4种:方法调用模式、函数调用模式、构造器调用模式、apply调用模式...

  • JS函数调用

    js 里函数调用有4种模式:方法调用、正常函数调用、构造器函数调用、apply/call 调用。无论哪种函数调用除...

  • this指向总结

    总结: 纯粹的函数调用:指向全局 作为对象方法的调用:指向对象(调用者) 构造函数调用:构造函数中的this指向n...

  • js里函数调用的四种模式

    js 里函数调用有4种模式:方法调用、正常函数调用、构造器函数调用、apply/call调用。同时,无论哪种函数调...

  • react中函数调用方法

    方式一:内联调用法 import React, { Component }from 'react'; class ...

  • Javascript学习笔记——4.5 调用表达式

    调用表达式(invocation expression)是一种调用或执行函数或方法的语法表示。 组成: 函数或方法...

  • JS this指向

    一、js中的四种调用模式s 构造函数调用:new Foo(); 对象方法调用:o.method(); 函数直接调用...

网友评论

    本文标题:react中三种函数调用方法总结

    本文链接:https://www.haomeiwen.com/subject/qgtthltx.html