表示一个留白,等待填充代码, 他在修改器(Modifier)中使用。 举个例子:
contract owned {
function owned() public { owner = msg.sender; }
address owner;
modifier onlyOwner {
require(
msg.sender == owner,
"Only owner can call this function."
);
_; // 使用了_
}
// 使用了onlyOwner 修饰
function withdraw() public onlyOwner {
msg.sender.transfer(10 ether);
}
}
withdraw() 展开之后:
function withdraw() public onlyOwner {
require(
msg.sender == owner,
"Only owner can call this function."
);
msg.sender.transfer(10 ether); // 填补了 _
}