sas语句文件导入宏语句_导入功能和导入语句之间的区别

sas语句文件导入宏语句

In my new Fundamentals of Angular course that is being released later this week, I cover lazy loading with Angular feature modules. In the section on lazy loading, we encounter the import() function. One of the things that can be confusing about this function is how it compares to the more common import statement.

在本周晚些时候发布的新的《 Angular基础知识》课程中,我将介绍Angular功能模块的延迟加载。 在延迟加载部分中,我们遇到了import()函数。 关于此功能可能引起混淆的一件事是它与更常见的import语句的比较方式。

I’ve previously written about the import statement and how it can be confusing. If you want a deeper dive on that, check out my blog here.

之前,我已经写过关于import语句以及它如何造成混淆的文章。 如果您想进一步了解,请在此处查看我的博客。

Let’s take a quick look at the import statement and the import function in JavaScript.

让我们快速看一下JavaScript中的import语句和import函数。

The import statement is what allows us to divide up our JavaScript into multiple files without using Script tags and ugly globals.

import语句使我们可以将JavaScript分成多个文件,而无需使用Script标签和丑陋的全局变量。

Generally, the import statement looks something like this and appears at the top of our files:

通常,import语句看起来像这样,并出现在文件的顶部:

Image for post

This statement is a static import. Whatever engine is processing our JavaScript to bundle up for delivery to the browser will crawl all the import statements we have in our files, and create one large bundle. In general, this is desirable. It allows for static analysis of our files, and advanced optimizations like tree shaking and dead code removal.

此语句是静态导入。 无论引擎正在处理我们JavaScript以便将其捆绑以交付给浏览器,它都会抓取文件中包含的所有导入语句,并创建一个大捆绑包。 通常,这是理想的。 它允许对我们的文件进行静态分析,并进行高级优化(例如,摇树和删除死代码)。

But it doesn’t allow us to either delay the inclusion of some code into our client-side project, or delay the download and loading of some of our code.

但这不允许我们延迟将某些代码包含到我们的客户端项目中,或延迟某些代码的下载和加载。

As projects get bigger and more complex and we use larger and larger frameworks and more and more third-party tools, our initial bundle can get unreasonably large. So finding the parts of our application that aren’t needed initially, and downloading them later can improve the initial performance of our application. And if the code is never needed, then we don’t have to force the user to download it.

随着项目变得越来越大,我们使用越来越大的框架和越来越多的第三方工具,我们最初的捆绑包可能会变得不合理。 因此,找到应用程序最初不需要的部分,然后再下载它们可以提高应用程序的初始性能。 而且,如果永远不需要该代码,那么我们就不必强迫用户下载它。

This functionality is enabled with the import function.

此功能通过导入功能启用。

The import function uses quite a different syntax than the static import statement.

导入功能使用的语法与静态导入语句完全不同。

It looks like this:

看起来像这样:

Image for post

Let’s go over this syntax, and what it’s doing.

让我们讨论一下这种语法及其作用。

First of all, the module path is probably the most likely place you’ll get something messed up. Getting the path wrong is easy since the path has to make sense to the server. So correctly getting the path to the module set is really the biggest potential mistake. You can either give a complete path to the file, or you can give a relative path in which case the browser will assume your base URL from your current domain. Any import statement executed like this will show up in the network tab of your browser as a typical JavaScript request.

首先,模块路径可能是最容易弄乱东西的地方。 错误的路径很容易,因为路径必须对服务器有意义。 因此,正确获取通往模块集的路径确实是最大的潜在错误。 您可以提供文件的完整路径,也可以提供相对路径,在这种情况下,浏览器将采用您当前域中的基本URL。 这样执行的所有import语句将作为典型JavaScript请求显示在浏览器的“网络”标签中。

Once the module has been downloaded, you now have a handle to the module itself and can do whatever you want with it in the then callback function of the promise. Note that the downloaded module is immediately parsed and executed by the browser without you doing anything. So if the code has any side effects, you can’t stop them from happening.

下载模块后,您现在可以使用模块本身的句柄,并且可以在promise的then回调函数中使用它进行所需的操作。 请注意,下载的模块将立即由浏览器解析并执行,而无需您进行任何操作。 因此,如果代码有任何副作用,则无法阻止它们的发生。

This is the mechanism used by many frameworks and libraries to download code on demand whenever needed.

这是许多框架和库用于在需要时按需下载代码的机制。

We use XHR calls to gather data, but we use the dynamic import function to gather additional code our project may need.

我们使用XHR调用来收集数据,但是我们使用动态导入功能来收集项目可能需要的其他代码。

The import function is used far less often than the static import statement, but it’s still extremely useful to understand.

导入功能的使用频率远低于静态导入语句,但了解它仍然非常有用。

Happy coding!

编码愉快!

Signup for my newsletter here.

在这里注册我的新闻通讯。

Visit Us: thinkster.io | Facebook: @gothinkster | Twitter: @GoThinkster

访问我们: thinkster.io | 脸书: @gothinkster | 推特: @GoThinkster

翻译自: https://medium.com/thinkster-io/the-difference-between-the-import-function-and-the-import-statement-3291151e6bc8

sas语句文件导入宏语句

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值