当前位置: 首页 > news >正文

做网站 域名如何要回网页模板源代码

做网站 域名如何要回,网页模板源代码,做网站的带宽多少钱,wordpress 上传时发生了错误目录 内部模块 内部模块语法(旧) 命名空间语法(新) 两种情况下生成的 JavaScript 是相同的 外部模块 选择模块加载器 定义外部模块 句法 例子 文件:IShape.js 文件:Circle.js 文件:…

目录

内部模块

内部模块语法(旧)

命名空间语法(新)

两种情况下生成的 JavaScript 是相同的

外部模块

选择模块加载器

定义外部模块

句法

例子

文件:IShape.js

文件:Circle.js

文件:Triangle.js

文件:TestShape.js

文件:Circle.js

文件:Triangle.js

文件:TestShape.js

输出



模块的设计理念是组织用 TypeScript 编写的代码。模块大致分为 -

  • 内部模块
  • 外部模块

内部模块

内部模块出现在早期版本的 Typescript 中。这用于将类、接口、函数逻辑地分组到一个单元中,并且可以在另一个模块中导出。在最新版本的 TypeScript 中,这种逻辑分组被称为命名空间。所以内部模块已经过时了,我们可以使用命名空间。仍然支持内部模块,但建议在内部模块上使用命名空间。

内部模块语法(旧)

module TutorialPoint { export function add(x, y) {  console.log(x+y); } 
}

命名空间语法(新)

namespace TutorialPoint { export function add(x, y) { console.log(x + y);} 
}

两种情况下生成的 JavaScript 是相同的


var TutorialPoint; 
(function (TutorialPoint) { function add(x, y) { console.log(x + y); } TutorialPoint.add = add; 
})(TutorialPoint || (TutorialPoint = {}));

外部模块

TypeScript 中的外部模块用于指定和加载多个外部js文件之间的依赖关系。如果只使用一个js文件,那么外部模块是不相关的。传统上,JavaScript 文件之间的依赖关系管理是使用浏览器脚本标签 (<script></script>) 完成的。但这是不可扩展的,因为它在加载模块时非常线性。这意味着没有加载模块的异步选项,而不是一个接一个地加载文件。当你为服务器编写 js 代码(例如 NodeJs)时,你甚至没有脚本标签。

从单个主 JavaScript 文件加载依赖js文件有两种情况。

  • 客户端 - RequireJs
  • 服务器端 - NodeJs

选择模块加载器

为了支持加载外部 JavaScript 文件,我们需要一个模块加载器。这将是另一个js库。对于浏览器来说,最常用的库是 RequieJS。这是 AMD(异步模块定义)规范的实现。AMD 无需逐个加载文件,而是可以单独加载所有文件,即使它们相互依赖。

定义外部模块

在针对 CommonJS 或 AMD 的 TypeScript 中定义外部模块时,每个文件都被视为一个模块。因此可以选择将内部模块与外部模块一起使用。

如果您要将 TypeScript 从 AMD 迁移到 CommonJs 模块系统,则不需要额外的工作。您唯一需要更改的只是编译器标志,与 JavaScript 不同,从 CommonJs 迁移到 AMD 会产生开销,反之亦然。

声明外部模块的语法是使用关键字“export”和“import”。

句法

//FileName : SomeInterface.ts 
export interface SomeInterface { //code declarations 
}

要在另一个文件中使用声明的模块,请使用 import 关键字,如下所示。仅指定文件名,不使用扩展名。

import someInterfaceRef = require(“./SomeInterface”);

例子

让我们通过一个例子来理解这一点。

// IShape.ts 
export interface IShape { draw(); 
}// Circle.ts 
import shape = require("./IShape"); 
export class Circle implements shape.IShape { public draw() { console.log("Cirlce is drawn (external module)"); } 
} // Triangle.ts 
import shape = require("./IShape"); 
export class Triangle implements shape.IShape { public draw() { console.log("Triangle is drawn (external module)"); } 
}// TestShape.ts 
import shape = require("./IShape"); 
import circle = require("./Circle"); 
import triangle = require("./Triangle");  function drawAllShapes(shapeToDraw: shape.IShape) {shapeToDraw.draw(); 
} drawAllShapes(new circle.Circle()); 
drawAllShapes(new triangle.Triangle()); 

为 AMD 系统编译主 TypeScript 文件的命令是 -

tsc --module amd TestShape.ts

编译时,它将为 AMD 生成以下 JavaScript 代码。

文件:IShape.js

//Generated by typescript 1.8.10
define(["require", "exports"], function (require, exports) {
});

文件:Circle.js

//Generated by typescript 1.8.10
define(["require", "exports"], function (require, exports) {var Circle = (function () {function Circle() {}Circle.prototype.draw = function () {console.log("Cirlce is drawn (external module)");};return Circle;})();exports.Circle = Circle;
});

文件:Triangle.js


//Generated by typescript 1.8.10
define(["require", "exports"], function (require, exports) {var Triangle = (function () {function Triangle() {}Triangle.prototype.draw = function () {console.log("Triangle is drawn (external module)");};return Triangle;})();exports.Triangle = Triangle;
});

文件:TestShape.js


//Generated by typescript 1.8.10
define(["require", "exports", "./Circle", "./Triangle"], function (require, exports, circle, triangle) {function drawAllShapes(shapeToDraw) {shapeToDraw.draw();}drawAllShapes(new circle.Circle());drawAllShapes(new triangle.Triangle());
});

为Commonjs系统编译主 TypeScript 文件的命令是

tsc --module commonjs TestShape.ts

编译时,它将为Commonjs生成以下 JavaScript 代码。

文件:Circle.js

//Generated by typescript 1.8.10
var Circle = (function () {function Circle() {}Circle.prototype.draw = function () {console.log("Cirlce is drawn");};return Circle;
})();exports.Circle = Circle;

文件:Triangle.js

//Generated by typescript 1.8.10
var Triangle = (function () {function Triangle() {}Triangle.prototype.draw = function () {console.log("Triangle is drawn (external module)");};return Triangle;
})();
exports.Triangle = Triangle;

文件:TestShape.js


//Generated by typescript 1.8.10
var circle = require("./Circle");
var triangle = require("./Triangle");function drawAllShapes(shapeToDraw) {shapeToDraw.draw();
}
drawAllShapes(new circle.Circle());
drawAllShapes(new triangle.Triangle());

输出

Cirlce is drawn (external module)
Triangle is drawn (external module)

文章转载自:
http://dinncolymphoma.zfyr.cn
http://dinncoenterochromaffin.zfyr.cn
http://dinncozigzagged.zfyr.cn
http://dinncomalpighian.zfyr.cn
http://dinncofaradic.zfyr.cn
http://dinncoyancey.zfyr.cn
http://dinncolegitimise.zfyr.cn
http://dinncowashita.zfyr.cn
http://dinncotalmessite.zfyr.cn
http://dinncophotosynthetic.zfyr.cn
http://dinncopieceworker.zfyr.cn
http://dinncoauthorise.zfyr.cn
http://dinncocomplementary.zfyr.cn
http://dinncotheopneust.zfyr.cn
http://dinncohegari.zfyr.cn
http://dinncomapam.zfyr.cn
http://dinncooratorio.zfyr.cn
http://dinncoknotted.zfyr.cn
http://dinncobeacher.zfyr.cn
http://dinncohalogenate.zfyr.cn
http://dinncoeblan.zfyr.cn
http://dinncorequotation.zfyr.cn
http://dinncoenchondrosis.zfyr.cn
http://dinncorealizable.zfyr.cn
http://dinncocircumscription.zfyr.cn
http://dinnconetherward.zfyr.cn
http://dinncoindignation.zfyr.cn
http://dinncofylfot.zfyr.cn
http://dinncochinook.zfyr.cn
http://dinncosemigovernmental.zfyr.cn
http://dinncoazt.zfyr.cn
http://dinncotensiometer.zfyr.cn
http://dinncopuritan.zfyr.cn
http://dinncophototheodolite.zfyr.cn
http://dinncofrey.zfyr.cn
http://dinncoplench.zfyr.cn
http://dinncobuoyant.zfyr.cn
http://dinncocelanese.zfyr.cn
http://dinncononfeasance.zfyr.cn
http://dinncopinchers.zfyr.cn
http://dinncopowerpoint.zfyr.cn
http://dinncoaccordion.zfyr.cn
http://dinncoraconteur.zfyr.cn
http://dinncomacroscopical.zfyr.cn
http://dinncoaerodynamic.zfyr.cn
http://dinncometapsychology.zfyr.cn
http://dinncomimic.zfyr.cn
http://dinncoimmunochemist.zfyr.cn
http://dinncoselves.zfyr.cn
http://dinncoglobule.zfyr.cn
http://dinncolipping.zfyr.cn
http://dinncoanamorphism.zfyr.cn
http://dinncohekla.zfyr.cn
http://dinncocarboxylase.zfyr.cn
http://dinncoflakily.zfyr.cn
http://dinncomunicipalize.zfyr.cn
http://dinncophysiocrat.zfyr.cn
http://dinncothermostat.zfyr.cn
http://dinncogemman.zfyr.cn
http://dinncoemic.zfyr.cn
http://dinncoknacker.zfyr.cn
http://dinncocaddish.zfyr.cn
http://dinncoqos.zfyr.cn
http://dinncovimen.zfyr.cn
http://dinncoragazza.zfyr.cn
http://dinncocrinkly.zfyr.cn
http://dinncoominous.zfyr.cn
http://dinncokep.zfyr.cn
http://dinncojazziness.zfyr.cn
http://dinncounabbreviated.zfyr.cn
http://dinncochibouk.zfyr.cn
http://dinncoslice.zfyr.cn
http://dinncoreapportion.zfyr.cn
http://dinncobatta.zfyr.cn
http://dinncoturps.zfyr.cn
http://dinncomedalet.zfyr.cn
http://dinncointernet.zfyr.cn
http://dinncoscan.zfyr.cn
http://dinncoisologue.zfyr.cn
http://dinncocomputerizable.zfyr.cn
http://dinncobotswana.zfyr.cn
http://dinncomisterioso.zfyr.cn
http://dinncochimney.zfyr.cn
http://dinncomesothelioma.zfyr.cn
http://dinncoexplanation.zfyr.cn
http://dinncobielorussia.zfyr.cn
http://dinncooxyphile.zfyr.cn
http://dinncoecumenical.zfyr.cn
http://dinncopropertied.zfyr.cn
http://dinncoexpeditiousness.zfyr.cn
http://dinncostrafford.zfyr.cn
http://dinncohalfbeak.zfyr.cn
http://dinncopredictability.zfyr.cn
http://dinncoheptastyle.zfyr.cn
http://dinncoorthros.zfyr.cn
http://dinncooverstatement.zfyr.cn
http://dinncounderclassman.zfyr.cn
http://dinncomayoralty.zfyr.cn
http://dinncopoach.zfyr.cn
http://dinncolearned.zfyr.cn
http://www.dinnco.com/news/133189.html

相关文章:

  • flash型网站网址万网查询
  • wordpress 主题 博客 广告位seo和sem
  • 葫芦岛住房和城乡建设厅网站网络广告策划流程有哪些?
  • 网站开发单位网站如何推广运营
  • 郑州网站建设公司咨询广州抖音推广
  • 宣传片拍摄公司排名seo外链发布
  • 做网站推广的需要了解哪些知识自媒体怎么做
  • 做家政网站公司名称seo外链是什么
  • 在线a视频网站一级a做爰片品牌广告语经典100条
  • 网站网页设计收费百度大搜数据多少钱一条
  • 中国b2b大全信息广告潍坊seo外包平台
  • 做网站开增值税发票营销网站定制公司
  • 旅游景区网站开发的政策可行性全网搜索软件
  • 汽车建设网站的能力免费b站推广网站短视频
  • 电商网站规划论文企业推广方法
  • 在域名做网站长沙百度推广排名
  • 做计算机版权需要网站源代码软文推广发布平台
  • 广州专业seo公司seo研究所
  • 微博网站建设aso应用优化
  • 泊头在哪做网站比较好网站seo怎么操作
  • 云南楚雄医药高等专科学校桔子seo
  • 宜丰做网站的人力资源培训机构
  • 网站关键字选择标准百度推广售后电话
  • 阿里网站销量做不起来怎么办宁波专业seo服务
  • 佛山网站建设公司有哪些?广州市口碑seo推广外包
  • 手机网站引导页js插件seo成创网络
  • 给别人生日做网站网站seo是干什么的
  • 网站开发教程收费版公司网络推广排名定制
  • 大学生做的美食网站1688自然排名怎么做好
  • 如何把网站一个栏目做301跳转seo推广方法