我正在学习有关区块链的课程,其中包含以下代码。“ index:this.chain.length + 1”是什么意思?索引是对象newBlock中的变量吗?还是键值对?如果它是一个变量,为什么我们不简单地使用index = this.chain.length + 1?另外,对象newBlock的类型是什么?
function Blockchain()
{
this.chain=[];
this.newTranscations=[];
}
Blockchain.prototype.createNeBlock = function(nonce,previousBlockHash,hash)
{
const newBlock ={
index:this.chain.length+1,
timestamp:Date.now(),
// all of the transactions in this block will be the transactions that waiting to be put in a block
transactions:this.newTranscations,
// nonce is hust a number giving proof of the transaction
nonce:nonce,
hash:hash,
previousBlockHash: previousBlockHash
}
// As we move all the pending transactions to the new block, we clear this array
this.newTranscations=[];
this.chain.push(newBlock);
return newBlock;
}
var Box = {
"playdoh":{"playdoh":["none", "some", "none", "none", "some"]}
};
一盒又一盒的Playdoh,您正在研究Objects / Arrays / Maps。
要将以上内容称为“
console.log(Box["playdoh"]["playdoh"][0]);
= none
console.log(Box["playdoh"]["playdoh"][4]);
= some
console.log(Box["playdoh"]["playdoh"][5]);
= null (undefined)
是相同的
console.log(Box.playdoh.playdoh[0]);
= none
console.log(Box.playdoh.playdoh[4]);
= some
console.log(Box.playdoh.playdoh[5]);
= null (undefined)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句