Loading...
This site is best viewed in a modern browser with JavaScript enabled.
Something went wrong while trying to load the full version of this site. Try hard-refreshing this page to fix the error.
今天在看lua-resty-balancer的代码是 看到这段代码,不知道此处用package.loaded.的作用何在为什么要这么写呢
iihelpcc
spacewanderlzx
local chash_up = package.loaded.my_clash_up
相当于 local chash_up = require "my_clash_up"
因为 require 之后的模块会缓存到全局的 package.loaded 表里。
你看到的这个是示例代码,这么写可以省略掉一些无关的内容,突出重点。
当然日常开发中一般不会直接修改 package.loaded。
在 2017年7月20日星期四 UTC+8上午11:06:31,cheng ye写道: