首页 > 问答 > 正文
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<code> const Title=React.createClass({
<code>
const
Title=React.createClass({
getDefaults: ()=> {
return{
return
{
title:'hello world'
title:
'hello world'
}
},
render:()=>{
return <h1>{this.props.title}</h1>
<h1>{this.props.title}</h1>
})
ReactDOM.render(
<Title/>,
document.getElementById('app6')
document.getElementById(
'app6'
)
此种情况下报错:Cannot read property 'props' of undefined
此种情况下报错:Cannot read property
'props'
of undefined
</code>
**请问:
<code>(1)此种情况下箭头函数和this是否可以一起使用?
(2)如果可以一起使用请问有何种解决方法?**</code>
巴扎黑2017-07-05 10:39:12
可以改成
<code>render() {
console.log(this);
}</code>
PHP中文网2017-07-05 10:39:12
万恶的ES2015!!!给你翻一下。
19
20
<code>function template(config) {
function
template(config) {
var self = this;
var
self = this;
Object.keys(config).forEach(function (key) {
Object.keys(config).forEach(
(key) {
self[key] = config[key];
});
function factory() {
factory() {
factory.create = function (config) {
factory.create =
(config) {
return new template(config);
new
template(config);
var instance = factory.create({
instance = factory.create({
title: 'instance1',
'instance1'
,
method: () => {
instance.method();</code>
method() {
基础多看看,其实理解并不难