“.then(() => Storage.deployed())”在 Javascript 中的实际含义是什么?

What does ".then(() => Storage.deployed())" actually mean in 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));
    }

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

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

定义

An arrow function expression is a syntactically compact alternative to a regular function expression, although without its own bindings to the this, arguments, super, or new.target keywords. Arrow function expressions are ill suited as methods, and they cannot be used as constructors.

Read more about arrow functions

.then()

定义:

The then() method returns a Promise. It takes up to two arguments: callback functions for the success and failure cases of the Promise.

Read more about Promise.prototype.then()

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

右边的箭头(=>)表示箭头函数,与你可能更熟悉的匿名函数(function() { ...body })非常相似。

它们的行为非常相似,除了匿名函数会更改 this 指向的内容,而箭头函数不会。在这个例子中,使用哪个并不重要,但箭头函数通常受到青睐,因为它允许更简单的代码。