首页 > 解决方案 > “.then(() => Storage.deployed())”在 Javascript 中的实际含义是什么?

问题描述

我正在学习 Solidity,部署脚本说这样的话,

var Storage = artifacts.require("./Storage.sol");
var InfoManager = artifacts.require("./InfoManager.sol");

    module.exports = function(deployer) {

        // Deploy the Storage contract
        deployer.deploy(Storage)
            // Wait until the storage contract is deployed
            .then(() => Storage.deployed())
            // Deploy the InfoManager contract, while passing the address of the
            // Storage contract
            .then(() => deployer.deploy(InfoManager, Storage.address));
    }

而且我似乎无法谷歌右箭头字符“=>”。

标签: javascriptsoliditytruffle

解决方案


() =>是 Javascript 中的箭头函数。

定义

箭头函数表达式是正则函数表达式的语法紧凑替代方案,尽管它没有绑定到 this、arguments、super 或 new.target 关键字。箭头函数表达式不适合用作方法,它们不能用作构造函数。

阅读有关箭头函数的更多信息

.then()

定义:

then() 方法返回一个 Promise。它最多需要两个参数:Promise 成功和失败情况的回调函数。

阅读更多关于 Promise.prototype.then()

发生的事情是,当deployer.deploy(Storage)promise 解决后,您将函数storage.deployed()作为回调函数执行。


推荐阅读