- Learn Blockchain Programming with JavaScript
- Eric Traub
- 134字
- 2021-06-10 18:40:36
Building the getLastBlock method
Now, the next method that we are going to add to our Blockchain constructor function will be the getLastBlock. This method will simply return the last block in our blockchain to us. Follow the below mentioned steps to build the method:
- Go to our dev/blockchain.js file, and after our createNewBlock method, add the following:
Blockchain.prototype.getLastBlock = function () {
}
- Inside of this getLastBlock method, we will type the following highlighted line of code:
Blockchain.prototype.getLastBlock = function () {
return this.chain[this.chain.length - 1];
}
The [this.chain.length - 1]; in this preceding code defines the position of the block in the chain, which, in our case, is the previous block, therefore negated by 1. This method is simple and straightforward, and we'll use it in later chapters.
推薦閱讀
- Java范例大全
- Java應(yīng)用與實(shí)戰(zhàn)
- Oracle Exadata性能優(yōu)化
- Android和PHP開發(fā)最佳實(shí)踐(第2版)
- 單片機(jī)C語(yǔ)言程序設(shè)計(jì)實(shí)訓(xùn)100例:基于STC8051+Proteus仿真與實(shí)戰(zhàn)
- Python零基礎(chǔ)快樂學(xué)習(xí)之旅(K12實(shí)戰(zhàn)訓(xùn)練)
- Java虛擬機(jī)字節(jié)碼:從入門到實(shí)戰(zhàn)
- Learning Firefox OS Application Development
- 零基礎(chǔ)學(xué)Java(第4版)
- Hands-On Functional Programming with TypeScript
- 前端HTML+CSS修煉之道(視頻同步+直播)
- Orleans:構(gòu)建高性能分布式Actor服務(wù)
- Laravel Application Development Blueprints
- Learning Nessus for Penetration Testing
- Instant Automapper