javascript-React中的匿名类
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript-React中的匿名类,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1143字,纯文字阅读大概需要2分钟。
内容图文
我听说过匿名函数,但是匿名类的概念对我来说是新的.例如,我们这里有一个看起来像这样的HOC.
import React, { Component } from 'react';
const withClass = (WrappedComponent, className) => {
return class extends Component {
render () {
return (
<div className={className}>
<WrappedComponent {...this.props} />
</div>
)
}
}
}
[题]
在这里,我无法理解此行的含义返回类extend Component {(我知道React的extends组件,{component})
有人可以解释一下它的一般功能吗?如果描述很模糊或简短,请告诉我.
解决方法:
Here, I am unable to understand meaning of this line
return class extends Component {
Can someone explain me what it does generally?
它定义了一个没有名称的类,并从withClass函数返回它.
也就是说,它做到了这一点,但是全部是在一个表达式中完成的,而没有给该类起一个名字:
import React, { Component } from 'react';
const withClass = (WrappedComponent, className) => {
class TheClass extends Component {
render () {
return (
<div className={className}>
<WrappedComponent {...this.props} />
</div>
)
}
}
return TheClass;
}
您可以这样使用它:
const MyClass = withClass(SomeComponent, "foo");
…您可以这样使用:
<MyClass foo="bar"/>
…你会得到
<div className="foo">
<SomeComponent foo="bar" />
</div>
…呈现时.
内容总结
以上是互联网集市为您收集整理的javascript-React中的匿名类全部内容,希望文章能够帮你解决javascript-React中的匿名类所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。