admin管理员组文章数量:1024166
I got this error message when I'm trying to initialize an object in the class ponent.
Error message
Failed to load bundle(http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false) with error:(SyntaxError: /blockchain/node_modules/react-native/App.js: Unexpected token (9:6)
My code
App.js
import Block from './block.js'
export default class App extends Component {
let genesisBlock = new Block(); //error here
let blockchain = new Blockchain(genesisBlock);
render() {
return (
</View>
);
}
}
block.js
export default class Block {
constructor() {
this.index = 0
this.previousHash = ""
this.hash = ""
this.nonce = 0
this.transactions = []
}
addTransaction(transaction) {
this.transactions.push(transaction)
}
get key() {
return JSON.stringify(this.transactions) + this.index + this.previousHash + this.nonce
}
}
But if I remove let
, it said variable genesisBlock not found
.
Reference:
I got this error message when I'm trying to initialize an object in the class ponent.
Error message
Failed to load bundle(http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false) with error:(SyntaxError: /blockchain/node_modules/react-native/App.js: Unexpected token (9:6)
My code
App.js
import Block from './block.js'
export default class App extends Component {
let genesisBlock = new Block(); //error here
let blockchain = new Blockchain(genesisBlock);
render() {
return (
</View>
);
}
}
block.js
export default class Block {
constructor() {
this.index = 0
this.previousHash = ""
this.hash = ""
this.nonce = 0
this.transactions = []
}
addTransaction(transaction) {
this.transactions.push(transaction)
}
get key() {
return JSON.stringify(this.transactions) + this.index + this.previousHash + this.nonce
}
}
But if I remove let
, it said variable genesisBlock not found
.
Reference: https://github./datomnurdin/blockchain-reactnative
Share Improve this question edited Dec 22, 2018 at 13:04 halfer 20.4k19 gold badges109 silver badges202 bronze badges asked Dec 18, 2018 at 21:25 NurdinNurdin 23.9k47 gold badges140 silver badges315 bronze badges 2-
genesisBlock = new Block();
... no let needed (or var) – Wainage Commented Dec 18, 2018 at 21:45 - already done but still same. any sample code? – Nurdin Commented Dec 18, 2018 at 21:48
2 Answers
Reset to default 2Try:
import Block from './block.js'
export default class App extends Component {
constructor(){
super()
this.genesisBlock = new Block();
this.blockchain = new Blockchain(this.genesisBlock);
}
render() {
return (
<View/>
);
}
}
Your render has a closing View tag with no opening one.
I got this error message when I'm trying to initialize an object in the class ponent.
Error message
Failed to load bundle(http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false) with error:(SyntaxError: /blockchain/node_modules/react-native/App.js: Unexpected token (9:6)
My code
App.js
import Block from './block.js'
export default class App extends Component {
let genesisBlock = new Block(); //error here
let blockchain = new Blockchain(genesisBlock);
render() {
return (
</View>
);
}
}
block.js
export default class Block {
constructor() {
this.index = 0
this.previousHash = ""
this.hash = ""
this.nonce = 0
this.transactions = []
}
addTransaction(transaction) {
this.transactions.push(transaction)
}
get key() {
return JSON.stringify(this.transactions) + this.index + this.previousHash + this.nonce
}
}
But if I remove let
, it said variable genesisBlock not found
.
Reference:
I got this error message when I'm trying to initialize an object in the class ponent.
Error message
Failed to load bundle(http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false) with error:(SyntaxError: /blockchain/node_modules/react-native/App.js: Unexpected token (9:6)
My code
App.js
import Block from './block.js'
export default class App extends Component {
let genesisBlock = new Block(); //error here
let blockchain = new Blockchain(genesisBlock);
render() {
return (
</View>
);
}
}
block.js
export default class Block {
constructor() {
this.index = 0
this.previousHash = ""
this.hash = ""
this.nonce = 0
this.transactions = []
}
addTransaction(transaction) {
this.transactions.push(transaction)
}
get key() {
return JSON.stringify(this.transactions) + this.index + this.previousHash + this.nonce
}
}
But if I remove let
, it said variable genesisBlock not found
.
Reference: https://github./datomnurdin/blockchain-reactnative
Share Improve this question edited Dec 22, 2018 at 13:04 halfer 20.4k19 gold badges109 silver badges202 bronze badges asked Dec 18, 2018 at 21:25 NurdinNurdin 23.9k47 gold badges140 silver badges315 bronze badges 2-
genesisBlock = new Block();
... no let needed (or var) – Wainage Commented Dec 18, 2018 at 21:45 - already done but still same. any sample code? – Nurdin Commented Dec 18, 2018 at 21:48
2 Answers
Reset to default 2Try:
import Block from './block.js'
export default class App extends Component {
constructor(){
super()
this.genesisBlock = new Block();
this.blockchain = new Blockchain(this.genesisBlock);
}
render() {
return (
<View/>
);
}
}
Your render has a closing View tag with no opening one.
本文标签: javascriptReact NativeHow to initialize object in class componentStack Overflow
版权声明:本文标题:javascript - React Native - How to initialize object in class component? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745600298a2158417.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论