alias, require, and import

alias, require, and import

In order to facilitate software reuse, Elixir provides three directives (alias, require and import) plus a macro called use summarized below:

# Alias the module so it can be called as Bar instead of Foo.Bar
alias Foo.Bar, as: Bar

# Require the module in order to use its macros
require Foo

# Import functions from Foo so they can be called without the `Foo.` prefix
import Foo

# Invokes the custom code defined in Foo as an extension point
use Foo

We are going to explore them in detail now. Keep in mind the first three are called directives because they have lexical scope, while use is a common extension point.

alias

登录查看完整内容