[英]Elixir - What does the 'use' keyword do?
I suspect it's an elementary question, but it's been hard to find a succinct, canonical answer online. 我怀疑这是一个基本问题,但很难在网上找到一个简洁,规范的答案。
From what little I understand; 从我理解的一点点来看;
Can anyone clarify? 任何人都可以澄清吗?
It require
s the given module and then calls the __using__/1
callback on it allowing the module to inject some code into the current context. 它
require
给定模块,然后在其上调用__using__/1
回调,允许模块将一些代码注入当前上下文。 See https://elixir-lang.org/getting-started/alias-require-and-import.html#use . 请参阅https://elixir-lang.org/getting-started/alias-require-and-import.html#use 。
Example: 例:
defmodule Test do
use Utility, argument: :value
end
is about the same as 与...大致相同
defmodule Test do
require Utility
Utility.__using__(argument: :value)
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.