I have one file which is block.js:
class Block{
constructor(timeStamp, lastBlockHash, thisBlockData, thisBlockHash){
this.timeStamp = timeStamp;
this.lastBlockHash = lastBlockHash;
this.thisBlockData = thisBlockData;
this.thisBlockHash = thisBlockHash;
}
static genesis(){
return new this(Date.now(), "---", "genesis block", "hash of the genesis");
}
}
I have another file blockchain.js where I have the following:
const Block = require('./block');
class BlockChain{
constructor() {
this.chain = BlockInstance.genesis();
}
}
and i have a test file where I am doing:
const Block = require("./block.js");
const BlockChain = require("./blockchain.js");
console.log(BlockChain.chain);
I get a "undefined" object in the print output.. this is really driving me nuts as i have already spent more than 4 hours on it.. if anyone can solve this mystery for me then a round of beers on me..
Cheers, alchemist
newkeyword for creating aBlockChaininstance. The class itself doesn't havechainproperty, it's instances have!