├── .classpath ├── .project ├── .settings ├── .jsdtscope ├── org.eclipse.jdt.core.prefs ├── org.eclipse.wst.common.component ├── org.eclipse.wst.common.project.facet.core.xml ├── org.eclipse.wst.jsdt.ui.superType.container └── org.eclipse.wst.jsdt.ui.superType.name └── WebContent ├── BasicTypes ├── html │ ├── test1.html │ ├── test2.html │ └── test3.html ├── test1.js ├── test1.ts ├── test2.js ├── test2.ts ├── test3.js └── test3.ts ├── Classes ├── html │ ├── test1.html │ ├── test2.html │ ├── test3.html │ ├── test4.html │ ├── test5.html │ └── test6.html ├── test1.js ├── test1.ts ├── test2.js ├── test2.ts ├── test3.js ├── test3.ts ├── test4.js ├── test4.ts ├── test5.js ├── test5.ts ├── test6.js └── test6.ts ├── Compatibility ├── test-1.js └── test-1.ts ├── Function ├── html │ ├── test1.html │ ├── test2.html │ ├── test3.html │ └── test4.html ├── test-1.js ├── test-1.ts ├── test-2.js ├── test-2.ts ├── test-3.js ├── test-3.ts ├── test-4.js └── test-4.ts ├── Generics ├── html │ ├── test1.html │ ├── test2.html │ ├── test3.html │ └── test4.html ├── test-1.js ├── test-1.ts ├── test-2.js ├── test-2.ts ├── test-3.js ├── test-3.ts ├── test-4.js └── test-4.ts ├── Interfaces ├── html │ ├── test1.html │ ├── test2.html │ ├── test3.html │ ├── test4.html │ ├── test5.html │ └── test6.html ├── test1.js ├── test1.ts ├── test2.js ├── test2.ts ├── test3.js ├── test3.ts ├── test4.js ├── test4.ts ├── test5.js ├── test5.ts ├── test6.js ├── test6.ts ├── test7.js └── test7.ts ├── META-INF └── MANIFEST.MF ├── Merging ├── html │ └── test1.html ├── test-1.js ├── test-1.ts ├── test-2.js └── test-2.ts ├── Mixins ├── html │ └── test1.html ├── test-1.js └── test-1.ts ├── Modules ├── html │ ├── test1.html │ ├── test2.html │ ├── test3.html │ ├── test4.html │ ├── test5.html │ └── test6.html ├── test-1.js ├── test-1.ts ├── test-2.js ├── test-2.ts ├── test-3.js ├── test-3.ts ├── test-4.js ├── test-4.ts ├── test-5.js ├── test-5.ts ├── test-6.js ├── test-6.ts ├── test1 │ ├── LettersOnlyValidator.js │ ├── LettersOnlyValidator.ts │ ├── Validation.js │ ├── Validation.ts │ ├── ZipCodeValidator.js │ └── ZipCodeValidator.ts ├── test2 │ ├── ValidationUtils.js │ └── ValidationUtils.ts ├── test3 │ ├── EmailValidator.js │ ├── EmailValidator.ts │ ├── TelValidator.js │ ├── TelValidator.ts │ ├── ValidationUtils3.js │ └── ValidationUtils3.ts ├── test4 │ ├── EmailValidator4.js │ ├── EmailValidator4.ts │ ├── TelValidator4.js │ ├── TelValidator4.ts │ ├── ValidationUtils4.js │ └── ValidationUtils4.ts ├── test5 │ ├── Aliasing.js │ └── Aliasing.ts └── test6 │ ├── D3.d.ts │ └── node.d.ts ├── plugins ├── curl.js ├── jquery-2.1.4.min.js ├── require.js └── typescript │ └── typings │ └── jquery.d.ts └── readme.txt /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | typescript 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.jsdt.core.javascriptValidator 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.common.project.facet.core.builder 20 | 21 | 22 | 23 | 24 | org.eclipse.wst.validation.validationbuilder 25 | 26 | 27 | 28 | 29 | com.palantir.typescript.typeScriptBuilder 30 | 31 | 32 | 33 | 34 | 35 | org.eclipse.jem.workbench.JavaEMFNature 36 | org.eclipse.wst.common.modulecore.ModuleCoreNature 37 | org.eclipse.wst.common.project.facet.core.nature 38 | org.eclipse.jdt.core.javanature 39 | org.eclipse.wst.jsdt.core.jsNature 40 | com.palantir.typescript.typeScriptNature 41 | 42 | 43 | -------------------------------------------------------------------------------- /.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 4 | org.eclipse.jdt.core.compiler.compliance=1.7 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.7 8 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /WebContent/BasicTypes/html/test1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /WebContent/BasicTypes/html/test2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
ageusernameadddrss
27龙梅子广东省广州
23 |
24 | 25 | -------------------------------------------------------------------------------- /WebContent/BasicTypes/html/test3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
ageusernameadddrss
27龙梅子广东省广州
23 |
24 | 25 | 26 | -------------------------------------------------------------------------------- /WebContent/BasicTypes/test1.js: -------------------------------------------------------------------------------- 1 | /** 2 | *@date:2015-07-16 3 | *@Author:liangjilong 4 | *============================================================================== 5 | *==================================TypeScript - 基本类型======================= 6 | *============================================================================== 7 | */ 8 | //对于程序来说我们需要基本的数据单元,如:numbers, strings, structures, boolean 等数据结构。 9 | //在TypeScript中我们支持很多你所期望在JavaScript中所拥有的数据类型系统。 10 | //var isFlag:boolean=false;这个 : 号代表应该是代表继承的意思,从C#的.cs文件可以看出来, 11 | //public class IndexController : Controller,Typescript也是微软开发出来的一个超级js 12 | //1、声明一个boolean类型默认值是false 13 | //在JavaScript和TypeScript中也具有最基本的逻辑断言值true/false,采用’boolean’类型。 14 | var isFlag = false; 15 | //2、声明一个number类型值 16 | //如JavaScript,TypeScript所有的数值类型采用浮点型计数,其类型为‘number’。 17 | var orderNumber = 100; 18 | //3、声明一个String类型 19 | //在webpages的JavaScript或者服务端的应用程序最基本的功能就是处理文本数据。在其他语言中大多使用’string’去代表文本数据类型。 20 | //TypeScript和JavaScript一样也是用双引号(“)或者单引号包裹文本数据 21 | var userName = "龙梅子"; 22 | //4、数组Array 23 | //在TypeScript中如JavaScript一样允许我们操结合操作。数组类型可以使用下边两种方式之一 24 | //第一种方式,你可以在数据类型之后带上’[]‘: 25 | var list = [1, 2, 3]; 26 | //第二种方式,也可以采用泛型的数组类型: 27 | var list1 = [1, 2, 3]; //泛型数组 28 | //5、枚举Enum 29 | //TypeScript为JavaScript新增了枚举这种标准的集合数据类型。和在c#中一样,枚举是为一组数值类型一组更友好的名称: 30 | // 31 | //------------------------------ 32 | var Color; 33 | (function (Color) { 34 | Color[Color["Red"] = 0] = "Red"; 35 | Color[Color["Green"] = 1] = "Green"; 36 | Color[Color["Blue"] = 2] = "Blue"; 37 | })(Color || (Color = {})); 38 | ; //enum关键字 枚举对象{声明变量} 39 | var c1 = Color.Green; //从枚举里面拿出绿色出来赋给一个叫c的变量 40 | //---------手动枚举所有值都设置--------------------- 41 | //默认枚举类型其实数值从0开始,你可以可用手动设置某一个成员的数值。例如我们可以将上文的起始值定为1: 42 | var Color1; 43 | (function (Color1) { 44 | Color1[Color1["Red"] = 1] = "Red"; 45 | Color1[Color1["Green"] = 2] = "Green"; 46 | Color1[Color1["Blue"] = 4] = "Blue"; 47 | })(Color1 || (Color1 = {})); 48 | ; 49 | var c2 = Color1.Green; 50 | //---------手动设置全部的枚举成员:--------------------- 51 | var Color2; 52 | (function (Color2) { 53 | Color2[Color2["Red"] = 1] = "Red"; 54 | Color2[Color2["Green"] = 2] = "Green"; 55 | Color2[Color2["Blue"] = 3] = "Blue"; 56 | })(Color2 || (Color2 = {})); 57 | ; 58 | var colorName = Color2[2]; 59 | alert(colorName); 60 | /** 61 | *我们可能需要描述变量的类型,当我们编写的应用程序,我们可能不知道。 62 | *这些值可能来自动态内容,例如从用户或第三方库。在这种情况下,我们要退出类型检查的, 63 | *让价值观通过编译时检查,要做到这一点,我们的标签,这些与'任何'类型: 64 | */ 65 | //6、any 66 | //any’类型是一种强大的兼容存在的JavaScript库的类型系统。他允许跳过TypeScript的编译时类型的检查。 67 | //‘any’类型对于我们只知道部分数据类型,但是不是所有的数据类型的类型系统。如一个混合了多种类型的集合数组 68 | var notSure = 4; //notSure这个是不确定的值,默认先给一个数字4 69 | notSure = "this string"; //改变这个值为this string 70 | notSure = false; //最终确定的值是一个boolean值. 71 | //------------------ 72 | var list2 = [1, true, "free"]; 73 | list2[1] = 100; 74 | //7、void和‘any’相对的数据类型则是’Void‘,它代表没有任何数据类型。我们常用的一个方法没有任何返回值: 75 | //,格式如:function doMain:void{} 76 | function warnUser() { 77 | alert("This is my void"); 78 | } 79 | -------------------------------------------------------------------------------- /WebContent/BasicTypes/test1.ts: -------------------------------------------------------------------------------- 1 | /** 2 | *@date:2015-07-16 3 | *@Author:liangjilong 4 | *============================================================================== 5 | *==================================TypeScript - 基本类型======================= 6 | *============================================================================== 7 | */ 8 | 9 | //对于程序来说我们需要基本的数据单元,如:numbers, strings, structures, boolean 等数据结构。 10 | //在TypeScript中我们支持很多你所期望在JavaScript中所拥有的数据类型系统。 11 | //var isFlag:boolean=false;这个 : 号代表应该是代表继承的意思,从C#的.cs文件可以看出来, 12 | //public class IndexController : Controller,Typescript也是微软开发出来的一个超级js 13 | 14 | //1、声明一个boolean类型默认值是false 15 | //在JavaScript和TypeScript中也具有最基本的逻辑断言值true/false,采用’boolean’类型。 16 | var isFlag:boolean=false; 17 | 18 | //2、声明一个number类型值 19 | //如JavaScript,TypeScript所有的数值类型采用浮点型计数,其类型为‘number’。 20 | 21 | var orderNumber:number=100; 22 | 23 | //3、声明一个String类型 24 | //在webpages的JavaScript或者服务端的应用程序最基本的功能就是处理文本数据。在其他语言中大多使用’string’去代表文本数据类型。 25 | //TypeScript和JavaScript一样也是用双引号(“)或者单引号包裹文本数据 26 | var userName:string="龙梅子"; 27 | 28 | //4、数组Array 29 | //在TypeScript中如JavaScript一样允许我们操结合操作。数组类型可以使用下边两种方式之一 30 | //第一种方式,你可以在数据类型之后带上’[]‘: 31 | var list:number[] = [1, 2, 3]; 32 | //第二种方式,也可以采用泛型的数组类型: 33 | var list1:Array = [1, 2, 3];//泛型数组 34 | 35 | //5、枚举Enum 36 | //TypeScript为JavaScript新增了枚举这种标准的集合数据类型。和在c#中一样,枚举是为一组数值类型一组更友好的名称: 37 | // 38 | 39 | //------------------------------ 40 | enum Color {Red, Green, Blue};//enum关键字 枚举对象{声明变量} 41 | var c1: Color = Color.Green;//从枚举里面拿出绿色出来赋给一个叫c的变量 42 | 43 | //---------手动枚举所有值都设置--------------------- 44 | //默认枚举类型其实数值从0开始,你可以可用手动设置某一个成员的数值。例如我们可以将上文的起始值定为1: 45 | enum Color1 {Red = 1, Green = 2, Blue = 4}; 46 | var c2: Color1 = Color1.Green; 47 | 48 | //---------手动设置全部的枚举成员:--------------------- 49 | enum Color2 {Red = 1, Green, Blue}; 50 | var colorName: string = Color2[2]; 51 | 52 | alert(colorName); 53 | 54 | 55 | /** 56 | *我们可能需要描述变量的类型,当我们编写的应用程序,我们可能不知道。 57 | *这些值可能来自动态内容,例如从用户或第三方库。在这种情况下,我们要退出类型检查的, 58 | *让价值观通过编译时检查,要做到这一点,我们的标签,这些与'任何'类型: 59 | */ 60 | 61 | //6、any 62 | //any’类型是一种强大的兼容存在的JavaScript库的类型系统。他允许跳过TypeScript的编译时类型的检查。 63 | //‘any’类型对于我们只知道部分数据类型,但是不是所有的数据类型的类型系统。如一个混合了多种类型的集合数组 64 | var notSure: any = 4;//notSure这个是不确定的值,默认先给一个数字4 65 | notSure = "this string";//改变这个值为this string 66 | notSure = false; //最终确定的值是一个boolean值. 67 | //------------------ 68 | 69 | var list2:any[] = [1, true, "free"]; 70 | 71 | list2[1] = 100; 72 | 73 | 74 | //7、void和‘any’相对的数据类型则是’Void‘,它代表没有任何数据类型。我们常用的一个方法没有任何返回值: 75 | //,格式如:function doMain:void{} 76 | 77 | function warnUser(): void { 78 | alert("This is my void"); 79 | } 80 | 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /WebContent/BasicTypes/test2.js: -------------------------------------------------------------------------------- 1 | /****使用reference和path引入jquery.d.ts文件使用jquery$就不会报错.**/ 2 | /// 3 | /** 4 | * ts的void,string结合jquery的使用. 5 | * 6 | */ 7 | /***返回void值***/ 8 | function setTableRowHtml1() { 9 | var userName = ""; 10 | $("tr").each(function () { 11 | userName = $(this).find("td:eq(1)").html(); 12 | }); 13 | alert(userName); 14 | } 15 | /***返回string一个值***/ 16 | function setTableRowHtml2() { 17 | var userName = ""; 18 | $("tr").each(function () { 19 | userName = $(this).find("td:eq(1)").html(); 20 | }); 21 | return userName; 22 | } 23 | //---jquery执行. 24 | $(function () { 25 | //setTableRowHtml1(); 26 | var userName = setTableRowHtml2(); 27 | alert(userName); 28 | }); 29 | -------------------------------------------------------------------------------- /WebContent/BasicTypes/test2.ts: -------------------------------------------------------------------------------- 1 | /****使用reference和path引入jquery.d.ts文件使用jquery$就不会报错.**/ 2 | 3 | /// 4 | 5 | /** 6 | * ts的void,string结合jquery的使用. 7 | * 8 | */ 9 | 10 | 11 | /***返回void值***/ 12 | function setTableRowHtml1():void{ 13 | var userName:string=""; 14 | $("tr").each(function(){ 15 | userName=$(this).find("td:eq(1)").html(); 16 | }); 17 | alert(userName); 18 | } 19 | 20 | /***返回string一个值***/ 21 | function setTableRowHtml2():string{ 22 | var userName:string=""; 23 | $("tr").each(function(){ 24 | userName=$(this).find("td:eq(1)").html(); 25 | }); 26 | return userName; 27 | } 28 | 29 | //---jquery执行. 30 | $(function(){ 31 | //setTableRowHtml1(); 32 | 33 | var userName=setTableRowHtml2(); 34 | alert(userName); 35 | }); -------------------------------------------------------------------------------- /WebContent/BasicTypes/test3.js: -------------------------------------------------------------------------------- 1 | /****使用reference和path引入jquery.d.ts文件使用jquery.d.ts声明的的$,不引就报错.**/ 2 | /// 3 | //var colorList:Array=["red","blue","green","yellow"];//string类型 4 | var colorList = ["red", "blue", "green", "yellow"]; //any不知道类型 5 | //---测试数组打印出来控制台/ 6 | function testArray() { 7 | $.each(colorList, function (key, val) { 8 | console.log(key + "=" + val); 9 | }); 10 | $(colorList).each(function (key, val) { 11 | console.log(key + "=" + val); 12 | }); 13 | } 14 | /***返回一个值***/ 15 | function setTableRowColor() { 16 | $("tr").each(function () { 17 | //找到tr下面的所有td的第二个列都加上背景blue,字体颜色加上red 18 | $(this).find("td:eq(1)").css({ color: "red", background: "blue" }); 19 | }); 20 | } 21 | function setTableRowColor1() { 22 | $("tr").each(function () { 23 | for (var i = 0; i < colorList.length; i++) { 24 | //找到tr下面的所有td的第二个列都加上背景blue,颜色就加上green色 25 | if (i == 1) { 26 | $(this).find("td:eq(1)").css({ color: colorList[i], background: colorList[i + 1] }); 27 | } 28 | } 29 | }); 30 | } 31 | $(document).ready(function () { 32 | testArray(); 33 | setTableRowColor(); 34 | //setTableRowColor1(); 35 | }); 36 | -------------------------------------------------------------------------------- /WebContent/BasicTypes/test3.ts: -------------------------------------------------------------------------------- 1 | /****使用reference和path引入jquery.d.ts文件使用jquery.d.ts声明的的$,不引就报错.**/ 2 | /// 3 | 4 | //var colorList:Array=["red","blue","green","yellow"];//string类型 5 | var colorList:Array=["red","blue","green","yellow"];//any不知道类型 6 | 7 | //---测试数组打印出来控制台/ 8 | function testArray():void{ 9 | 10 | $.each(colorList,function(key,val){ 11 | console.log(key+"="+val); 12 | }); 13 | 14 | $(colorList).each(function(key,val){ 15 | console.log(key+"="+val); 16 | }); 17 | } 18 | 19 | /***返回一个值***/ 20 | function setTableRowColor():void{ 21 | $("tr").each(function(){ 22 | //找到tr下面的所有td的第二个列都加上背景blue,字体颜色加上red 23 | $(this).find("td:eq(1)").css({ color: "red", background: "blue" }); 24 | }); 25 | } 26 | 27 | function setTableRowColor1():void{ 28 | $("tr").each(function(){ 29 | for(var i=0;i 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /WebContent/Classes/html/test2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 |
11 | 12 | -------------------------------------------------------------------------------- /WebContent/Classes/html/test3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 |
11 | 12 | -------------------------------------------------------------------------------- /WebContent/Classes/html/test4.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 |
11 |
12 |
13 | 14 | -------------------------------------------------------------------------------- /WebContent/Classes/html/test5.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 |
11 |
12 |
13 | 14 | -------------------------------------------------------------------------------- /WebContent/Classes/html/test6.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 |
11 |
12 |
13 | 14 | -------------------------------------------------------------------------------- /WebContent/Classes/test1.js: -------------------------------------------------------------------------------- 1 | /// 2 | //--这个是简单的class 3 | var Employee = (function () { 4 | function Employee() { 5 | } 6 | return Employee; 7 | })(); 8 | var employee = new Employee(); 9 | employee.fullName = "Long long"; //赋值 10 | //说明这个属性是存在的.. 11 | if (employee.fullName) { 12 | alert(employee.fullName); 13 | } 14 | -------------------------------------------------------------------------------- /WebContent/Classes/test1.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | //--这个是简单的class 4 | class Employee { 5 | fullName: string; 6 | } 7 | 8 | var employee = new Employee(); 9 | employee.fullName = "Long long";//赋值 10 | 11 | 12 | //说明这个属性是存在的.. 13 | if (employee.fullName) { 14 | alert(employee.fullName); 15 | } -------------------------------------------------------------------------------- /WebContent/Classes/test2.js: -------------------------------------------------------------------------------- 1 | /// 2 | //--class和constructor构造器使用。 3 | var UserInfo = (function () { 4 | //--默认的构造方法.. 5 | function UserInfo(msg) { 6 | this.username = msg; //从构造方法传一个用户字符串过去. 7 | } 8 | UserInfo.prototype.getUserInfo = function () { 9 | return "欢迎您, " + this.username; 10 | }; 11 | return UserInfo; 12 | })(); 13 | function printMsg() { 14 | var resMsg = ""; 15 | var g = new UserInfo("龙梅子"); //创建一个UserInfo对象,并且构造函数必须要传一个字符串. 16 | resMsg = g.getUserInfo(); //调用对象方法. 17 | return resMsg; 18 | } 19 | /****************jQuery-执行..**********************/ 20 | $(function () { 21 | var result = printMsg(); 22 | $("#msg").html("" + result + ""); 23 | }); 24 | -------------------------------------------------------------------------------- /WebContent/Classes/test2.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | //--class和constructor构造器使用。 4 | 5 | class UserInfo{ 6 | username:string; 7 | //--默认的构造方法.. 8 | constructor(msg : string){ 9 | this.username=msg;//从构造方法传一个用户字符串过去. 10 | } 11 | getUserInfo(){ 12 | return "欢迎您, " + this.username; 13 | } 14 | } 15 | 16 | function printMsg():string{ 17 | var resMsg:string=""; 18 | 19 | var g=new UserInfo("龙梅子");//创建一个UserInfo对象,并且构造函数必须要传一个字符串. 20 | 21 | resMsg=g.getUserInfo();//调用对象方法. 22 | return resMsg; 23 | } 24 | 25 | /****************jQuery-执行..**********************/ 26 | 27 | $(function(){ 28 | var result=printMsg(); 29 | $("#msg").html(""+result+""); 30 | 31 | }); -------------------------------------------------------------------------------- /WebContent/Classes/test3.js: -------------------------------------------------------------------------------- 1 | /// 2 | var __extends = (this && this.__extends) || function (d, b) { 3 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; 4 | function __() { this.constructor = d; } 5 | __.prototype = b.prototype; 6 | d.prototype = new __(); 7 | }; 8 | //------class与supper使用.---------------- 9 | //--动物类 10 | var Animal = (function () { 11 | //默认构造方法 12 | function Animal(theName) { 13 | this.name = theName; 14 | } 15 | //声明一个移动方法,并且传一个距离meters参数. 16 | Animal.prototype.move = function (meters) { 17 | if (meters === void 0) { meters = 0; } 18 | alert(this.name + " 跑了 " + meters + "米."); 19 | }; 20 | return Animal; 21 | })(); 22 | //--蛇 23 | var Snake = (function (_super) { 24 | __extends(Snake, _super); 25 | function Snake(name) { 26 | _super.call(this, name); 27 | } 28 | //蛇是移动了5米 29 | Snake.prototype.move = function (meters) { 30 | if (meters === void 0) { meters = 5; } 31 | alert("蛇进行跑....."); 32 | _super.prototype.move.call(this, meters); //调用Animal声明的move方法 33 | }; 34 | return Snake; 35 | })(Animal); 36 | //马 37 | var Horse = (function (_super) { 38 | __extends(Horse, _super); 39 | function Horse(name) { 40 | _super.call(this, name); 41 | } 42 | Horse.prototype.move = function (meters) { 43 | if (meters === void 0) { meters = 45; } 44 | alert("马进行跑..."); 45 | _super.prototype.move.call(this, meters); 46 | }; 47 | return Horse; 48 | })(Animal); 49 | var sam = new Snake("蛇加油"); 50 | var tom = new Horse("马加油"); //Animal 51 | sam.move(); // 52 | tom.move(38); //如果知道马跑多少米,给一个距离米,故马是跑了38米 53 | -------------------------------------------------------------------------------- /WebContent/Classes/test3.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | //------class与supper使用.---------------- 4 | 5 | //--动物类 6 | class Animal { 7 | name:string;//名称 8 | //默认构造方法 9 | constructor(theName: string) { 10 | this.name = theName; 11 | } 12 | //声明一个移动方法,并且传一个距离meters参数. 13 | move(meters: number = 0) { 14 | alert(this.name + " 跑了 " + meters + "米."); 15 | } 16 | } 17 | 18 | //--蛇 19 | class Snake extends Animal { 20 | constructor(name: string) { 21 | super(name); 22 | } 23 | //蛇是移动了5米 24 | move(meters = 5) { 25 | alert("蛇进行跑....."); 26 | super.move(meters);//调用Animal声明的move方法 27 | } 28 | } 29 | //马 30 | class Horse extends Animal { 31 | constructor(name: string) { 32 | super(name); 33 | } 34 | move(meters = 45) { 35 | alert("马进行跑..."); 36 | super.move(meters); 37 | } 38 | } 39 | 40 | var sam = new Snake("蛇加油"); 41 | 42 | var tom: Animal = new Horse("马加油");//Animal 43 | 44 | sam.move();// 45 | tom.move(38);//如果知道马跑多少米,给一个距离米,故马是跑了38米 -------------------------------------------------------------------------------- /WebContent/Classes/test4.js: -------------------------------------------------------------------------------- 1 | /// 2 | var __extends = (this && this.__extends) || function (d, b) { 3 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; 4 | function __() { this.constructor = d; } 5 | __.prototype = b.prototype; 6 | d.prototype = new __(); 7 | }; 8 | //------class与supper使用.---------------- 9 | var Person = (function () { 10 | //构造方法 11 | function Person(paramVal) { 12 | this.userName = paramVal; 13 | } 14 | //--声明一个getPersonInfo方法,并在声明age变量 15 | Person.prototype.getPersonInfo = function (age) { 16 | if (age === void 0) { age = 120; } 17 | return this.userName + "\n" + age; 18 | }; 19 | return Person; 20 | })(); 21 | var Student1 = (function (_super) { 22 | __extends(Student1, _super); 23 | function Student1(username) { 24 | _super.call(this, username); 25 | } 26 | Student1.prototype.getPersonInfo = function (age) { 27 | if (age === void 0) { age = 100; } 28 | var superMsg = _super.prototype.getPersonInfo.call(this, age); 29 | return this.userName + "\n" + age + "岁" + "\n\t\t" + "默认信息:" + superMsg; 30 | }; 31 | return Student1; 32 | })(Person); 33 | var Student2 = (function (_super) { 34 | __extends(Student2, _super); 35 | function Student2(username) { 36 | _super.call(this, username); 37 | } 38 | Student2.prototype.getPersonInfo = function (age) { 39 | if (age === void 0) { age = 120; } 40 | var superMsg = _super.prototype.getPersonInfo.call(this, age); 41 | return this.userName + "\n" + age + "岁" + "\n\t\t" + "默认信息:" + superMsg; 42 | }; 43 | return Student2; 44 | })(Person); 45 | var stu1 = new Student1("周伯通"); 46 | var stu2 = new Student2("老毒物"); 47 | var stuMsg1 = stu1.getPersonInfo(); 48 | var stuMsg2 = stu2.getPersonInfo(80); //传一个默认值给getPersonInfo方法 49 | $(function () { 50 | $("#msg1").html("" + stuMsg1 + ""); 51 | $("#msg2").html("" + stuMsg2 + ""); 52 | }); 53 | -------------------------------------------------------------------------------- /WebContent/Classes/test4.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | //------class与supper使用.---------------- 4 | 5 | class Person{ 6 | userName:string;//声明一个名称 7 | //构造方法 8 | constructor(paramVal:string){ 9 | this.userName=paramVal; 10 | } 11 | 12 | //--声明一个getPersonInfo方法,并在声明age变量 13 | getPersonInfo(age:number=120):string{ 14 | return this.userName+"\n"+age; 15 | } 16 | 17 | } 18 | 19 | class Student1 extends Person{ 20 | 21 | constructor(username:string){ 22 | super(username); 23 | } 24 | getPersonInfo(age=100){ 25 | var superMsg=super.getPersonInfo(age); 26 | return this.userName+"\n"+age+"岁"+"\n\t\t"+"默认信息:" +superMsg; 27 | } 28 | } 29 | class Student2 extends Person{ 30 | 31 | constructor(username:string){ 32 | super(username); 33 | } 34 | getPersonInfo(age=120){ 35 | var superMsg=super.getPersonInfo(age); 36 | return this.userName+"\n"+age+"岁"+"\n\t\t"+"默认信息:" +superMsg; 37 | } 38 | } 39 | 40 | var stu1=new Student1("周伯通"); 41 | var stu2=new Student2("老毒物"); 42 | 43 | var stuMsg1=stu1.getPersonInfo(); 44 | var stuMsg2=stu2.getPersonInfo(80);//传一个默认值给getPersonInfo方法 45 | 46 | $(function(){ 47 | 48 | $("#msg1").html(""+stuMsg1+""); 49 | $("#msg2").html(""+stuMsg2+""); 50 | }); 51 | -------------------------------------------------------------------------------- /WebContent/Classes/test5.js: -------------------------------------------------------------------------------- 1 | /// 2 | var __extends = (this && this.__extends) || function (d, b) { 3 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; 4 | function __() { this.constructor = d; } 5 | __.prototype = b.prototype; 6 | d.prototype = new __(); 7 | }; 8 | /** 9 | * public/private 10 | * 默认是public 11 | * 您可能已经注意到,在我们还没有使用这个词“公众”作出任何类可见的成员的上述例子。 12 | * 如C#语言要求每个成员被明确标记为'公共'可见。在打字稿,每个成员都是公共默认。 13 | * 您可能仍然标记成员的私人,所以你控制什么是公开可见的外部类的 14 | */ 15 | var MyAnimal = (function () { 16 | //构造方法 17 | function MyAnimal(theName) { 18 | this.theName = theName; 19 | this.name = theName; 20 | } 21 | MyAnimal.prototype.getMsg = function (name) { 22 | return this.name = name; 23 | }; 24 | return MyAnimal; 25 | })(); 26 | //犀牛 27 | var Rhino = (function (_super) { 28 | __extends(Rhino, _super); 29 | function Rhino() { 30 | _super.call(this, "犀牛"); 31 | } 32 | Rhino.prototype.getMsg = function (name) { 33 | return name; 34 | }; 35 | return Rhino; 36 | })(MyAnimal); 37 | //员工 38 | var Employees = (function () { 39 | //构造方法 40 | function Employees(theName) { 41 | this.name = theName; 42 | } 43 | return Employees; 44 | })(); 45 | var animal = new MyAnimal("山羊"); //Goat山羊 46 | var retMsg1 = animal.getMsg("鹿"); 47 | var rhino = new Rhino(); 48 | var employees = new Employees("洪七公"); 49 | animal = rhino; 50 | //animal = employees;//此时这个值不能赋给animal,并不能编译通过. 51 | $(function () { 52 | $("#msg1").html("" + retMsg1 + ""); 53 | }); 54 | -------------------------------------------------------------------------------- /WebContent/Classes/test5.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | /** 4 | * public/private 5 | * 默认是public 6 | * 您可能已经注意到,在我们还没有使用这个词“公众”作出任何类可见的成员的上述例子。 7 | * 如C#语言要求每个成员被明确标记为'公共'可见。在打字稿,每个成员都是公共默认。 8 | * 您可能仍然标记成员的私人,所以你控制什么是公开可见的外部类的 9 | */ 10 | class MyAnimal { 11 | private name:string; 12 | //构造方法 13 | constructor(private theName : string){ 14 | this.name = theName; 15 | } 16 | 17 | getMsg(name : string):string{ 18 | return this.name=name; 19 | } 20 | 21 | } 22 | //犀牛 23 | class Rhino extends MyAnimal{ 24 | constructor(){ 25 | super("犀牛"); 26 | } 27 | getMsg(name : string):string{ 28 | return name; 29 | } 30 | 31 | } 32 | //员工 33 | class Employees { 34 | private name:string; 35 | //构造方法 36 | constructor(theName : string) { 37 | this.name = theName; 38 | } 39 | } 40 | 41 | 42 | var animal = new MyAnimal("山羊");//Goat山羊 43 | var retMsg1=animal.getMsg("鹿"); 44 | 45 | var rhino = new Rhino(); 46 | 47 | var employees = new Employees("洪七公"); 48 | 49 | animal = rhino; 50 | //animal = employees;//此时这个值不能赋给animal,并不能编译通过. 51 | 52 | 53 | $(function(){ 54 | $("#msg1").html(""+retMsg1+""); 55 | 56 | }); 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /WebContent/Classes/test6.js: -------------------------------------------------------------------------------- 1 | /** 2 | *高级技巧 3 | *构造函数 4 | *当您声明一个类,你实际上是在同一时间创建多个声明。第一个是类的实例的类型 5 | */ 6 | var Greeter = (function () { 7 | function Greeter() { 8 | } 9 | Greeter.prototype.greet = function () { 10 | if (this.greeting) { 11 | return "Hello, " + this.greeting; 12 | } 13 | else { 14 | return Greeter.standardGreeting; 15 | } 16 | }; 17 | Greeter.standardGreeting = "Hello, there"; 18 | return Greeter; 19 | })(); 20 | var greeter1; 21 | greeter1 = new Greeter(); 22 | alert(greeter1.greet()); 23 | var greeterMaker = Greeter; 24 | greeterMaker.standardGreeting = "Hey there!"; 25 | var greeter2 = new greeterMaker(); 26 | alert(greeter2.greet()); 27 | -------------------------------------------------------------------------------- /WebContent/Classes/test6.ts: -------------------------------------------------------------------------------- 1 | /** 2 | *高级技巧 3 | *构造函数 4 | *当您声明一个类,你实际上是在同一时间创建多个声明。第一个是类的实例的类型 5 | */ 6 | 7 | class Greeter { 8 | static standardGreeting = "Hello, there"; 9 | greeting: string; 10 | greet() { 11 | if (this.greeting) { 12 | return "Hello, " + this.greeting; 13 | } 14 | else { 15 | return Greeter.standardGreeting; 16 | } 17 | } 18 | } 19 | 20 | var greeter1: Greeter; 21 | greeter1 = new Greeter(); 22 | alert(greeter1.greet()); 23 | 24 | var greeterMaker: typeof Greeter = Greeter; 25 | greeterMaker.standardGreeting = "Hey there!"; 26 | var greeter2:Greeter = new greeterMaker(); 27 | alert(greeter2.greet()); 28 | 29 | -------------------------------------------------------------------------------- /WebContent/Compatibility/test-1.js: -------------------------------------------------------------------------------- 1 | var x; 2 | //判断这个y的类型是{ name: string; location: string; } 3 | var y = { name: 'Alice', location: 'Seattle' }; 4 | x = y; 5 | var items = [1, 2, 3]; 6 | //不压迫强迫这些额外参数... 7 | items.forEach(function (item, index, array) { return console.log(item); }); 8 | // Should be OK! 9 | items.forEach(function (item) { return console.log(item); }); 10 | var k = function () { return ({ name: 'Alice' }); }; 11 | var z = function () { return ({ name: 'Alice', location: 'Seattle' }); }; 12 | k = z; // OK 13 | //z = k; //这k()方法缺少了location属性.所以赋给z()方法是会报错的. 14 | -------------------------------------------------------------------------------- /WebContent/Compatibility/test-1.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Type Compatibility 3 | * 类型比较. 4 | */ 5 | interface Named { 6 | name: string; 7 | } 8 | var x: Named; 9 | //判断这个y的类型是{ name: string; location: string; } 10 | var y = { name: 'Alice', location: 'Seattle' }; 11 | x = y; 12 | 13 | var items = [1, 2, 3]; 14 | 15 | //不压迫强迫这些额外参数... 16 | items.forEach((item, index, array) => console.log(item)); 17 | 18 | // Should be OK! 19 | items.forEach((item) => console.log(item)) 20 | 21 | var k = () => ({name: 'Alice'}); 22 | var z = () => ({name: 'Alice', location: 'Seattle'}); 23 | 24 | k = z; // OK 25 | //z = k; //这k()方法缺少了location属性.所以赋给z()方法是会报错的. 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /WebContent/Function/html/test1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 |
11 |
12 |
13 |
14 |
15 | 16 | -------------------------------------------------------------------------------- /WebContent/Function/html/test2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 |
11 |
12 |
13 |
14 |
15 | 16 | -------------------------------------------------------------------------------- /WebContent/Function/html/test3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 |
11 |
12 |
13 |
14 |
15 | 16 | -------------------------------------------------------------------------------- /WebContent/Function/html/test4.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 |
11 |
12 |
13 |
14 |
15 | 16 | -------------------------------------------------------------------------------- /WebContent/Function/test-1.js: -------------------------------------------------------------------------------- 1 | /*******声明一个add方法********/ 2 | function add(x, y) { 3 | return x + y; 4 | } 5 | /*******声明一个myAdd1方法********/ 6 | var myAdd1 = function (x, y) { 7 | return x + y; 8 | }; 9 | /*******声明一个myAdd2方法********/ 10 | //现在我们已经输入的功能,让我们写了完整类型的功能出来通过查看每件功能类型。 11 | var myAdd2 = function (x, y) { 12 | return x + y; 13 | }; 14 | var number3 = myAdd2(1, 3); 15 | $(function () { 16 | var number1 = add(1, 2); 17 | var number2 = myAdd1(1, 2); 18 | $("#msg1").html("" + number1 + ""); 19 | $("#msg2").html("" + number2 + ""); 20 | $("#msg3").html("" + number3 + ""); 21 | }); 22 | -------------------------------------------------------------------------------- /WebContent/Function/test-1.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | /*******声明一个add方法********/ 4 | function add(x: number, y: number): number { 5 | return x+y; 6 | } 7 | 8 | /*******声明一个myAdd1方法********/ 9 | var myAdd1 = function(x: number, y: number): number { 10 | return x+y; 11 | }; 12 | /*******声明一个myAdd2方法********/ 13 | //现在我们已经输入的功能,让我们写了完整类型的功能出来通过查看每件功能类型。 14 | var myAdd2: (x:number, y:number)=>number = function(x: number, y: number): number { 15 | return x+y; 16 | }; 17 | 18 | var number3=myAdd2(1,3); 19 | 20 | $(function () { 21 | 22 | var number1=add(1,2); 23 | var number2=myAdd1(1,2); 24 | 25 | $("#msg1").html(""+number1+""); 26 | $("#msg2").html(""+number2+""); 27 | $("#msg3").html(""+number3+""); 28 | 29 | }); 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /WebContent/Function/test-2.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 一、function没有返回值,却返回了,虽然在写function的的时候不报错,调用的时候就报Error 3 | * 不像JavaScript中,在打字稿每参数的函数被假定为所要求的功能。这并不意味着它不是一个“空”值, 4 | * 而是,当函数调用编译器将检查该用户已经提供了对每个参数的值。编译器还假定这些参数是将被传递给函数的唯一参数。 5 | * 总之,参数的函数的数目必须匹配的参数的函数需要的数量。 6 | */ 7 | function buildName1(firstName, lastName) { 8 | return firstName + " " + lastName; 9 | } 10 | //var result1 = buildName1("Bob"); //error, too few parameters 11 | //var result2 = buildName1("Bob", "Adams", "Sr."); //error, too many parameters 12 | //var result3 = buildName1("Bob", "Adams"); //ah, just right 13 | /** 14 | * Rest parameters 15 | * 其余的参数 16 | *在JavaScript中,每一个参数被认为是可选的,用户可以不用管它,因为他们认为合适的。当他们这样做,他们认为是不确定的。 17 | *我们可以通过使用得到打字稿这个功能'?“旁边的参数,我们想要可选。例如,我们说,我们要的姓氏是可选: 18 | */ 19 | function buildName2(firstName, lastName) { 20 | if (lastName) 21 | return firstName + " " + lastName; 22 | else 23 | return firstName; 24 | } 25 | var result1 = buildName2("Bob"); //works correctly now 26 | //var result2 = buildName2("Bob", "Adams", "Sr."); //error, too many parameters 27 | var result3 = buildName2("Bob", "Adams"); //ah, just right 28 | /** 29 | * 必需,可选和默认参数都有一个共同点:他们大约在同一时间谈论一个参数。有时候,你想与多个参数的工作作为一个群体 30 | * ,或者你可能不知道有多少参数的函数将最终取,在JavaScript中,你可以使用的参数变量,它是每一个函数体中可见 31 | * 在TypeScript:您可以收集这些参数汇集成一个变量 32 | */ 33 | function buildName3(firstName) { 34 | var restOfName = []; 35 | for (var _i = 1; _i < arguments.length; _i++) { 36 | restOfName[_i - 1] = arguments[_i]; 37 | } 38 | return firstName + " " + restOfName.join(" "); 39 | } 40 | var employeeName = buildName3("Joseph", "Samuel", "Lucas", "MacKinzie"); 41 | /** 42 | * Rest parameters 43 | * 其余的参数都被视为可选参数无边号码。你可能会离开他们,或者你想要的。编译器将建立你的下省略号(...) 44 | * 后给予的名称传递给函数的参数数组,允许你使用它在你的函数 45 | */ 46 | function buildName4(firstName) { 47 | var restOfName = []; 48 | for (var _i = 1; _i < arguments.length; _i++) { 49 | restOfName[_i - 1] = arguments[_i]; 50 | } 51 | return firstName + " " + restOfName.join(" "); 52 | } 53 | var buildNameFun = buildName4; 54 | -------------------------------------------------------------------------------- /WebContent/Function/test-2.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * 一、function没有返回值,却返回了,虽然在写function的的时候不报错,调用的时候就报Error 4 | * 不像JavaScript中,在打字稿每参数的函数被假定为所要求的功能。这并不意味着它不是一个“空”值, 5 | * 而是,当函数调用编译器将检查该用户已经提供了对每个参数的值。编译器还假定这些参数是将被传递给函数的唯一参数。 6 | * 总之,参数的函数的数目必须匹配的参数的函数需要的数量。 7 | */ 8 | function buildName1(firstName: string, lastName: string) { 9 | return firstName + " " + lastName; 10 | } 11 | 12 | //var result1 = buildName1("Bob"); //error, too few parameters 13 | //var result2 = buildName1("Bob", "Adams", "Sr."); //error, too many parameters 14 | //var result3 = buildName1("Bob", "Adams"); //ah, just right 15 | 16 | /** 17 | * Rest parameters 18 | * 其余的参数 19 | *在JavaScript中,每一个参数被认为是可选的,用户可以不用管它,因为他们认为合适的。当他们这样做,他们认为是不确定的。 20 | *我们可以通过使用得到打字稿这个功能'?“旁边的参数,我们想要可选。例如,我们说,我们要的姓氏是可选: 21 | */ 22 | function buildName2(firstName: string, lastName?: string) { 23 | if (lastName) 24 | return firstName + " " + lastName; 25 | else 26 | return firstName; 27 | } 28 | 29 | var result1 = buildName2("Bob"); //works correctly now 30 | //var result2 = buildName2("Bob", "Adams", "Sr."); //error, too many parameters 31 | var result3 = buildName2("Bob", "Adams"); //ah, just right 32 | 33 | 34 | 35 | /** 36 | * 必需,可选和默认参数都有一个共同点:他们大约在同一时间谈论一个参数。有时候,你想与多个参数的工作作为一个群体 37 | * ,或者你可能不知道有多少参数的函数将最终取,在JavaScript中,你可以使用的参数变量,它是每一个函数体中可见 38 | * 在TypeScript:您可以收集这些参数汇集成一个变量 39 | */ 40 | 41 | function buildName3(firstName: string, ...restOfName: string[]) { 42 | return firstName + " " + restOfName.join(" "); 43 | } 44 | 45 | var employeeName = buildName3("Joseph", "Samuel", "Lucas", "MacKinzie"); 46 | 47 | 48 | /** 49 | * Rest parameters 50 | * 其余的参数都被视为可选参数无边号码。你可能会离开他们,或者你想要的。编译器将建立你的下省略号(...) 51 | * 后给予的名称传递给函数的参数数组,允许你使用它在你的函数 52 | */ 53 | 54 | function buildName4(firstName: string, ...restOfName: string[]) { 55 | return firstName + " " + restOfName.join(" "); 56 | } 57 | 58 | var buildNameFun: (fname: string, ...rest: string[])=>string = buildName4; 59 | -------------------------------------------------------------------------------- /WebContent/Function/test-3.js: -------------------------------------------------------------------------------- 1 | /** 2 | * this的使用.. 3 | *在 JavaScript,this的变量一个函数被调用的变量。这使得它成为非常强大和灵活的功能, 4 | *但它是在总是具有了解,一个功能被执行的情况下的成本。这可以是出了名的混乱,例如,当一个函数被用作一个回调。 5 | */ 6 | function getMeMsg1() { 7 | var suits1 = ["hearts", "spades", "clubs", "diamonds"]; 8 | var deck1 = { 9 | suits: suits1, 10 | cards: Array(52), 11 | createCardPicker: function () { 12 | return function () { 13 | var pickedCard = Math.floor(Math.random() * 52); 14 | var pickedSuit = Math.floor(pickedCard / 13); 15 | return { suit: this.suits[pickedSuit], card: pickedCard % 13 }; 16 | }; 17 | } 18 | }; 19 | var cardPicker1 = deck1.createCardPicker(); 20 | var pickedCard1 = cardPicker1(); 21 | alert("card1: " + pickedCard1.card + " of " + pickedCard1.suit); 22 | } 23 | /** 24 | * 我们可以通过确保修复此功能被绑定到正确的'this'之前,我们返回函数供以后使用。这样一来, 25 | * 不管如何其以后使用时,它仍可以看到原来的“甲板”对象 26 | * 为了解决这个问题,我们切换函数表达式使用lambda语法(()=>{}),而不是JavaScript函数表达式。 27 | * 这将自动捕捉“这个”可被创建,而不是被调用时,它的功能时: 28 | */ 29 | function getMeMsg2() { 30 | var deck2 = { 31 | suits: ["hearts", "spades", "clubs", "diamonds"], 32 | cards: Array(52), 33 | createCardPicker: function () { 34 | var _this = this; 35 | //使用lambda表达式去捕捉this用法. 36 | return function () { 37 | var pickedCard = Math.floor(Math.random() * 52); 38 | var pickedSuit = Math.floor(pickedCard / 13); 39 | console.log(_this.suits[pickedSuit]); 40 | console.log(pickedCard % 13); 41 | return { suit: _this.suits[pickedSuit], card: pickedCard % 13 }; 42 | }; 43 | } 44 | }; 45 | var cardPicker2 = deck2.createCardPicker(); 46 | var pickedCard2 = cardPicker2(); 47 | alert("card2: " + pickedCard2.card + " of " + pickedCard2.suit); 48 | } 49 | $(function () { 50 | getMeMsg2(); 51 | }); 52 | -------------------------------------------------------------------------------- /WebContent/Function/test-3.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * this的使用.. 3 | *在 JavaScript,this的变量一个函数被调用的变量。这使得它成为非常强大和灵活的功能, 4 | *但它是在总是具有了解,一个功能被执行的情况下的成本。这可以是出了名的混乱,例如,当一个函数被用作一个回调。 5 | */ 6 | 7 | function getMeMsg1():void{ 8 | var suits1=["hearts", "spades", "clubs", "diamonds"]; 9 | 10 | var deck1 = { 11 | suits:suits1, 12 | cards: Array(52), 13 | createCardPicker: function() { 14 | return function() { 15 | var pickedCard = Math.floor(Math.random() * 52); 16 | var pickedSuit = Math.floor(pickedCard / 13); 17 | return {suit: this.suits[pickedSuit], card: pickedCard % 13}; 18 | } 19 | } 20 | } 21 | 22 | var cardPicker1 = deck1.createCardPicker(); 23 | var pickedCard1 = cardPicker1(); 24 | 25 | alert("card1: " + pickedCard1.card + " of " + pickedCard1.suit); 26 | 27 | } 28 | 29 | 30 | /** 31 | * 我们可以通过确保修复此功能被绑定到正确的'this'之前,我们返回函数供以后使用。这样一来, 32 | * 不管如何其以后使用时,它仍可以看到原来的“甲板”对象 33 | * 为了解决这个问题,我们切换函数表达式使用lambda语法(()=>{}),而不是JavaScript函数表达式。 34 | * 这将自动捕捉“这个”可被创建,而不是被调用时,它的功能时: 35 | */ 36 | 37 | function getMeMsg2():void{ 38 | var deck2 = { 39 | suits: ["hearts", "spades", "clubs", "diamonds"], 40 | cards: Array(52), 41 | createCardPicker: function() { 42 | //使用lambda表达式去捕捉this用法. 43 | return () => { 44 | var pickedCard = Math.floor(Math.random() * 52); 45 | var pickedSuit = Math.floor(pickedCard / 13); 46 | console.log(this.suits[pickedSuit]); 47 | console.log(pickedCard % 13); 48 | 49 | return {suit: this.suits[pickedSuit], card: pickedCard % 13}; 50 | } 51 | } 52 | } 53 | 54 | var cardPicker2 = deck2.createCardPicker(); 55 | var pickedCard2 = cardPicker2(); 56 | 57 | alert("card2: " + pickedCard2.card + " of " + pickedCard2.suit); 58 | 59 | } 60 | 61 | 62 | $(function(){ 63 | 64 | getMeMsg2(); 65 | }); 66 | 67 | 68 | -------------------------------------------------------------------------------- /WebContent/Function/test-4.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | *JavaScript是本质上是一种非常好的动态的语言。这并意味都通用的一个JavaScript函数返回基于对传入的参数的形状不同类型的对象。 4 | * 5 | */ 6 | var suits = ["hearts", "spades", "clubs", "diamonds"]; 7 | //--实例一 8 | function getThisMsgs1() { 9 | function pickCard1(x) { 10 | // 判断这个x是不是object/array 11 | if (typeof x == "object") { 12 | var pickedCard = Math.floor(Math.random() * x.length); 13 | return pickedCard; 14 | } 15 | else if (typeof x == "number") { 16 | var pickedSuit = Math.floor(x / 13); 17 | return { suit: suits[pickedSuit], card: x % 13 }; 18 | } 19 | } 20 | var myDeck1 = [{ suit: "diamonds", card: 2 }, { suit: "spades", card: 10 }, { suit: "hearts", card: 4 }]; 21 | var pickedCard1 = myDeck1[pickCard1(myDeck1)]; 22 | alert("card: " + pickedCard1.card + " of " + pickedCard1.suit); 23 | var pickedCard2 = pickCard1(15); 24 | alert("card: " + pickedCard2.card + " of " + pickedCard2.suit); 25 | } 26 | //--实例二 27 | function getThisMsgs2() { 28 | function pickCard(x) { 29 | // Check to see if we're working with an object/array 30 | // if so, they gave us the deck and we'll pick the card 31 | if (typeof x == "object") { 32 | var pickedCard = Math.floor(Math.random() * x.length); 33 | return pickedCard; 34 | } 35 | else if (typeof x == "number") { 36 | var pickedSuit = Math.floor(x / 13); 37 | return { suit: suits[pickedSuit], card: x % 13 }; 38 | } 39 | } 40 | var myDeck = [{ suit: "diamonds", card: 2 }, { suit: "spades", card: 10 }, { suit: "hearts", card: 4 }]; 41 | var pickedCard1 = myDeck[pickCard(myDeck)]; 42 | alert("card: " + pickedCard1.card + " of " + pickedCard1.suit); 43 | var pickedCard2 = pickCard(15); 44 | alert("card: " + pickedCard2.card + " of " + pickedCard2.suit); 45 | } 46 | $(function () { 47 | getThisMsgs2(); 48 | }); 49 | -------------------------------------------------------------------------------- /WebContent/Function/test-4.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | *JavaScript是本质上是一种非常好的动态的语言。这并意味都通用的一个JavaScript函数返回基于对传入的参数的形状不同类型的对象。 4 | * 5 | */ 6 | 7 | 8 | var suits = ["hearts", "spades", "clubs", "diamonds"]; 9 | 10 | //--实例一 11 | function getThisMsgs1():void{ 12 | 13 | function pickCard1(x): any { 14 | // 判断这个x是不是object/array 15 | if (typeof x == "object") { 16 | var pickedCard = Math.floor(Math.random() * x.length); 17 | return pickedCard; 18 | } 19 | // 判断 20 | else if (typeof x == "number") { 21 | var pickedSuit = Math.floor(x / 13); 22 | return { suit: suits[pickedSuit], card: x % 13 }; 23 | } 24 | } 25 | 26 | var myDeck1 = [{ suit: "diamonds", card: 2 }, { suit: "spades", card: 10 }, { suit: "hearts", card: 4 }]; 27 | var pickedCard1 = myDeck1[pickCard1(myDeck1)]; 28 | alert("card: " + pickedCard1.card + " of " + pickedCard1.suit); 29 | 30 | var pickedCard2 = pickCard1(15); 31 | alert("card: " + pickedCard2.card + " of " + pickedCard2.suit); 32 | 33 | } 34 | 35 | 36 | //--实例二 37 | function getThisMsgs2():void{ 38 | function pickCard(x: {suit: string; card: number; }[]): number; 39 | function pickCard(x: number): {suit: string; card: number; }; 40 | function pickCard(x): any { 41 | // Check to see if we're working with an object/array 42 | // if so, they gave us the deck and we'll pick the card 43 | if (typeof x == "object") { 44 | var pickedCard = Math.floor(Math.random() * x.length); 45 | return pickedCard; 46 | } 47 | // Otherwise just let them pick the card 48 | else if (typeof x == "number") { 49 | var pickedSuit = Math.floor(x / 13); 50 | return { suit: suits[pickedSuit], card: x % 13 }; 51 | } 52 | } 53 | 54 | var myDeck = [{ suit: "diamonds", card: 2 }, { suit: "spades", card: 10 }, { suit: "hearts", card: 4 }]; 55 | var pickedCard1 = myDeck[pickCard(myDeck)]; 56 | alert("card: " + pickedCard1.card + " of " + pickedCard1.suit); 57 | 58 | var pickedCard2 = pickCard(15); 59 | alert("card: " + pickedCard2.card + " of " + pickedCard2.suit); 60 | } 61 | 62 | 63 | 64 | 65 | 66 | $(function(){ 67 | getThisMsgs2(); 68 | 69 | }); 70 | -------------------------------------------------------------------------------- /WebContent/Generics/html/test1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 |
11 |
12 |
13 | 14 | -------------------------------------------------------------------------------- /WebContent/Generics/html/test2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 |
11 |
12 |
13 | 14 | -------------------------------------------------------------------------------- /WebContent/Generics/html/test3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 |
11 |
12 |
13 | 14 | -------------------------------------------------------------------------------- /WebContent/Generics/html/test4.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 |
11 |
12 |
13 | 14 | -------------------------------------------------------------------------------- /WebContent/Generics/test-1.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 没有泛型,我们要么必须给身份功能的特定类型 3 | */ 4 | function identity1(arg) { 5 | return arg; 6 | } 7 | /** 8 | * 或者:我们可以描述使用“任意”类型的标识功能: 9 | */ 10 | function identity2(arg) { 11 | return arg; 12 | } 13 | -------------------------------------------------------------------------------- /WebContent/Generics/test-1.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 没有泛型,我们要么必须给身份功能的特定类型 3 | */ 4 | 5 | function identity1(arg: number): number { 6 | return arg; 7 | } 8 | 9 | /** 10 | * 或者:我们可以描述使用“任意”类型的标识功能: 11 | */ 12 | function identity2(arg: any): any { 13 | return arg; 14 | } -------------------------------------------------------------------------------- /WebContent/Generics/test-2.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Working with Generic Type Variables 3 | * 与泛型类型变量 4 | */ 5 | function _identity1(arg) { 6 | return arg; 7 | } 8 | /** 9 | * 如果还想记录的说法“arg”与每个调用控制台的长度。我们也许会这样写 10 | */ 11 | function loggingIdentity1(arg) { 12 | // console.log(arg.length); // Error: T doesn't have .length 13 | return arg; 14 | } 15 | /** 16 | *当我们这样做时,编译器会给出我们,我们使用的是“ARG”的“.length”成员的错误,但远不具备,我们说,“ARG”有这样的成员。请记住,我们在前面说,这些类型变量站在任何和所有类型的,所以有人使用此功能可以通过在一个'数',而不是,它没有一个“.length”成员。 17 | *比方说,我们实际上已经预期该功能直接对T的阵列,而那件T的工作。由于我们正在使用的阵列,对象.length成员应该可用。我们可以这样描述这就像我们将创建其他类型的数组: 18 | */ 19 | function loggingIdentity2(arg) { 20 | console.log(arg.length); 21 | return arg; 22 | } 23 | /** 24 | *我们还可以写成这样的模式 ,一个数组.length,这样避免更多的错误 25 | */ 26 | function loggingIdentity3(arg) { 27 | console.log(arg.length); 28 | return arg; 29 | } 30 | -------------------------------------------------------------------------------- /WebContent/Generics/test-2.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Working with Generic Type Variables 3 | * 与泛型类型变量 4 | */ 5 | function _identity1(arg: T): T { 6 | return arg; 7 | } 8 | 9 | /** 10 | * 如果还想记录的说法“arg”与每个调用控制台的长度。我们也许会这样写 11 | */ 12 | function loggingIdentity1(arg: T): T { 13 | // console.log(arg.length); // Error: T doesn't have .length 14 | return arg; 15 | } 16 | 17 | 18 | /** 19 | *当我们这样做时,编译器会给出我们,我们使用的是“ARG”的“.length”成员的错误,但远不具备,我们说,“ARG”有这样的成员。请记住,我们在前面说,这些类型变量站在任何和所有类型的,所以有人使用此功能可以通过在一个'数',而不是,它没有一个“.length”成员。 20 | *比方说,我们实际上已经预期该功能直接对T的阵列,而那件T的工作。由于我们正在使用的阵列,对象.length成员应该可用。我们可以这样描述这就像我们将创建其他类型的数组: 21 | */ 22 | 23 | function loggingIdentity2(arg: T[]): T[] { 24 | console.log(arg.length); 25 | return arg; 26 | } 27 | 28 | /** 29 | *我们还可以写成这样的模式 ,一个数组.length,这样避免更多的错误 30 | */ 31 | function loggingIdentity3(arg: Array): Array { 32 | console.log(arg.length); 33 | return arg; 34 | } 35 | -------------------------------------------------------------------------------- /WebContent/Generics/test-3.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Generic Types 3 | */ 4 | /** 5 | * 6 | *在前面的章节中,我们创建了工作的范围内的类型的通用身份的功能。在本节中,我们将探讨的功能类型本身, 7 | *以及如何创建通用接口.通用函数的类型就像那些非通用功能,具有类型参数首家上市,类似于函数声明 8 | */ 9 | function identity3(arg) { 10 | return arg; 11 | } 12 | var myIdentity3 = identity3; 13 | /** 14 | * 我们也可以用不同的名称在类型一般类型参数,所以只要类型变量的数量和如何类型变量用于排队 15 | */ 16 | function identity4(arg) { 17 | return arg; 18 | } 19 | var myIdentity4 = identity4; 20 | /** 21 | * 我们也可以写泛型类型为对象文本类型的调用签名 22 | */ 23 | function identity5(arg) { 24 | return arg; 25 | } 26 | var myIdentity5 = identity5; 27 | function identity6(arg) { 28 | return arg; 29 | } 30 | var myIdentity6 = identity6; 31 | function identity7(arg) { 32 | return arg; 33 | } 34 | var myIdentity7 = identity7; 35 | -------------------------------------------------------------------------------- /WebContent/Generics/test-3.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Generic Types 3 | */ 4 | 5 | /** 6 | * 7 | *在前面的章节中,我们创建了工作的范围内的类型的通用身份的功能。在本节中,我们将探讨的功能类型本身, 8 | *以及如何创建通用接口.通用函数的类型就像那些非通用功能,具有类型参数首家上市,类似于函数声明 9 | */ 10 | 11 | function identity3(arg: T): T { 12 | return arg; 13 | } 14 | 15 | var myIdentity3: (arg: T)=>T = identity3; 16 | 17 | 18 | /** 19 | * 我们也可以用不同的名称在类型一般类型参数,所以只要类型变量的数量和如何类型变量用于排队 20 | */ 21 | 22 | function identity4(arg: T): T { 23 | return arg; 24 | } 25 | 26 | var myIdentity4: (arg: U)=>U = identity4; 27 | 28 | /** 29 | * 我们也可以写泛型类型为对象文本类型的调用签名 30 | */ 31 | 32 | function identity5(arg: T): T { 33 | return arg; 34 | } 35 | 36 | var myIdentity5: {(arg: T): T} = identity5; 37 | 38 | 39 | 40 | /** 41 | * 这使我们写我们的第一个通用interface接口。让我们以字面对象从以前的例子,它移动到一个界面: 42 | */ 43 | 44 | interface GenericIdentityFn1 { 45 | (arg: T): T; 46 | } 47 | 48 | function identity6(arg: T): T { 49 | return arg; 50 | } 51 | 52 | var myIdentity6: GenericIdentityFn1 = identity6; 53 | 54 | 55 | /** 56 | * 在一个类似的例子,我们可能要移动的通用参数是整个接口的参数。这让我们看到什么类型,我们是在通用 57 | * (如:Dictionary而不仅仅是字典)。这使得该类型参数可见的接口的所有其他成员。 58 | */ 59 | 60 | interface GenericIdentityFn2 { 61 | (arg: T): T; 62 | } 63 | 64 | function identity7(arg: T): T { 65 | return arg; 66 | } 67 | 68 | var myIdentity7: GenericIdentityFn2 = identity7; 69 | 70 | 71 | -------------------------------------------------------------------------------- /WebContent/Generics/test-4.js: -------------------------------------------------------------------------------- 1 | /** 2 | *Generic Classes 3 | * 4 | */ 5 | var __extends = (this && this.__extends) || function (d, b) { 6 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; 7 | function __() { this.constructor = d; } 8 | __.prototype = b.prototype; 9 | d.prototype = new __(); 10 | }; 11 | //泛型类也有类似形状的通用接口。泛型类在尖括号泛型类型参数列表 12 | //--T 13 | var GenericNumber = (function () { 14 | function GenericNumber() { 15 | } 16 | return GenericNumber; 17 | })(); 18 | /*------number数字类型-----*/ 19 | var myGenericNumber = new GenericNumber(); 20 | myGenericNumber.zeroValue = 0; 21 | myGenericNumber.add = function (x, y) { return x + y; }; 22 | /*------string字符串类型-----*/ 23 | var stringNumeric = new GenericNumber(); 24 | stringNumeric.zeroValue = ""; 25 | stringNumeric.add = function (x, y) { return x + y; }; 26 | alert(stringNumeric.add(stringNumeric.zeroValue, "test")); 27 | //-function用extends关键继承这个ILength接口约束。。 28 | function loggingIdentity(arg) { 29 | console.log(arg.length); //获取这个length值 30 | return arg; 31 | } 32 | //调用这个loggingIdentity方法 33 | var object = loggingIdentity({ length: 10, value: 3 }); 34 | /** 35 | *在使用泛型类的类型 36 | *当我们用typescript去创建工厂的时候,因此有必要通过其构造函数来引用类类型 37 | */ 38 | function create(c) { 39 | return new c(); 40 | } 41 | /** 42 | *使用:一个更高级的示例使用原型属性来推断和约束的构造函数和类类型的实例侧之间的关系 43 | */ 44 | //养蜂人 45 | var BeeKeeper = (function () { 46 | function BeeKeeper() { 47 | } 48 | return BeeKeeper; 49 | })(); 50 | //动物管理人. 51 | var ZooKeeper = (function () { 52 | function ZooKeeper() { 53 | } 54 | return ZooKeeper; 55 | })(); 56 | //动物 57 | var Animals = (function () { 58 | function Animals() { 59 | } 60 | return Animals; 61 | })(); 62 | //蜜蜂 63 | var Bee = (function (_super) { 64 | __extends(Bee, _super); 65 | function Bee() { 66 | _super.apply(this, arguments); 67 | } 68 | return Bee; 69 | })(Animals); 70 | //狮子 71 | var Lion = (function (_super) { 72 | __extends(Lion, _super); 73 | function Lion() { 74 | _super.apply(this, arguments); 75 | } 76 | return Lion; 77 | })(Animals); 78 | //管理人. 79 | function findKeeper(a) { 80 | return a.prototype.keeper; 81 | } 82 | //findKeeper(Lion).nametag; // 检查类型! 83 | /** 84 | *jQuery---- 85 | * 86 | */ 87 | $(function () { 88 | var len = $(object).attr("length"); //获取这个length值 89 | var value = $(object).attr("value"); //获取这个value值 90 | //alert(len); 91 | //alert(value); 92 | //var obj1:Animals=Lion; 93 | //console.log( findKeeper(Lion).nametag);//检查类型! 94 | }); 95 | -------------------------------------------------------------------------------- /WebContent/Generics/test-4.ts: -------------------------------------------------------------------------------- 1 | /** 2 | *Generic Classes 3 | * 4 | */ 5 | 6 | //泛型类也有类似形状的通用接口。泛型类在尖括号泛型类型参数列表 7 | 8 | //--T 9 | class GenericNumber { 10 | zeroValue: T; 11 | add: (x: T, y: T) => T; 12 | } 13 | /*------number数字类型-----*/ 14 | var myGenericNumber = new GenericNumber(); 15 | myGenericNumber.zeroValue = 0; 16 | myGenericNumber.add = function(x, y) { return x + y; }; 17 | 18 | /*------string字符串类型-----*/ 19 | var stringNumeric = new GenericNumber(); 20 | stringNumeric.zeroValue = ""; 21 | stringNumeric.add = function(x, y) { return x + y; }; 22 | 23 | alert(stringNumeric.add(stringNumeric.zeroValue, "test")); 24 | 25 | 26 | //-----------------Generic Constraints---- 27 | 28 | /*****声明一个接口,来约束**********/ 29 | interface ILength { 30 | length: number;//声明一个number类型 31 | } 32 | 33 | //-function用extends关键继承这个ILength接口约束。。 34 | function loggingIdentity(arg: T): T { 35 | console.log(arg.length); //获取这个length值 36 | return arg; 37 | } 38 | 39 | //调用这个loggingIdentity方法 40 | var object=loggingIdentity({length: 10, value: 3}); 41 | 42 | 43 | /** 44 | *在使用泛型类的类型 45 | *当我们用typescript去创建工厂的时候,因此有必要通过其构造函数来引用类类型 46 | */ 47 | 48 | 49 | function create(c: {new(): T; }): T { 50 | return new c(); 51 | } 52 | 53 | 54 | /** 55 | *使用:一个更高级的示例使用原型属性来推断和约束的构造函数和类类型的实例侧之间的关系 56 | */ 57 | 58 | //养蜂人 59 | class BeeKeeper { 60 | hasMask: boolean; 61 | } 62 | //动物管理人. 63 | class ZooKeeper { 64 | nametag: string; 65 | } 66 | //动物 67 | class Animals { 68 | numLegs: number; 69 | } 70 | //蜜蜂 71 | class Bee extends Animals { 72 | keeper: BeeKeeper; 73 | } 74 | //狮子 75 | class Lion extends Animals { 76 | keeper: ZooKeeper; 77 | } 78 | //管理人. 79 | function findKeeper (a: {new(): A; 80 | prototype: {keeper: K}}): K { 81 | 82 | return a.prototype.keeper; 83 | } 84 | 85 | //findKeeper(Lion).nametag; // 检查类型! 86 | 87 | 88 | 89 | /** 90 | *jQuery---- 91 | * 92 | */ 93 | $(function(){ 94 | 95 | var len=$(object).attr("length");//获取这个length值 96 | var value=$(object).attr("value");//获取这个value值 97 | 98 | //alert(len); 99 | //alert(value); 100 | 101 | //var obj1:Animals=Lion; 102 | 103 | //console.log( findKeeper(Lion).nametag);//检查类型! 104 | 105 | }); -------------------------------------------------------------------------------- /WebContent/Interfaces/html/test1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /WebContent/Interfaces/html/test2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /WebContent/Interfaces/html/test3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /WebContent/Interfaces/html/test4.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /WebContent/Interfaces/html/test5.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /WebContent/Interfaces/html/test6.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /WebContent/Interfaces/test1.js: -------------------------------------------------------------------------------- 1 | /*********获取用户信息*******/ 2 | function getUserInfo(user) { 3 | return user.age + "======" + user.userName; 4 | } 5 | //用一个数组对象作为一个user对象传值过getUserInfo函数方法..参数必须要以接口IUserInfo对应上. 6 | //少传一个参数,typescript会自动帮你检测报错,如果用纯javascript去写的话,不会报错,ts大大减少检查js问题 7 | //如:var userObj={userName:'周伯通'};//error 8 | var userObj = { userName: '周伯通', age: 100 }; 9 | $(function () { 10 | //定义变量接收值.. 11 | var userInfo = getUserInfo(userObj); 12 | console.log(userInfo); 13 | }); 14 | -------------------------------------------------------------------------------- /WebContent/Interfaces/test1.ts: -------------------------------------------------------------------------------- 1 | 2 | /**--声明一个接口,这个接口不会在js上面出现,只会在显示一个user对象在getUserInfo*/ 3 | interface IUserInfo{ 4 | age : any;//定义一个任何变量的age. 5 | userName :string;//定义一个username. 6 | } 7 | 8 | /*********获取用户信息*******/ 9 | function getUserInfo(user : IUserInfo):string{ 10 | return user.age+"======"+user.userName; 11 | } 12 | 13 | //用一个数组对象作为一个user对象传值过getUserInfo函数方法..参数必须要以接口IUserInfo对应上. 14 | //少传一个参数,typescript会自动帮你检测报错,如果用纯javascript去写的话,不会报错,ts大大减少检查js问题 15 | //如:var userObj={userName:'周伯通'};//error 16 | 17 | var userObj={userName:'周伯通',age:100}; 18 | 19 | $(function(){ 20 | //定义变量接收值.. 21 | var userInfo:string= getUserInfo(userObj); 22 | console.log(userInfo); 23 | }); 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /WebContent/Interfaces/test2.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Not all properties of an interface may be required. 3 | * Some exist under certain conditions or may not be there at all 4 | *并非需要一个接口的所有属性。在某些条件下的一些存在或可以不存在的。 5 | *这句话说的是:就算你SquareConfig接口定义的变量是color,到调用createSquare的时候你给color1变量照样可以取出z值来 6 | *这个值只不过是:默认的newSquare的white值,如果是一样的color变量他就会取出你给赋格对象的color(red) 7 | */ 8 | /***************创建一个对象function.**************/ 9 | function createSquare(config) { 10 | //此时newSquare里面的参数必须与 :后面里面的参数名称一致. 11 | var newSquare = { color: "white", area: 100 }; 12 | if (config.color) { 13 | newSquare.color = config.color; 14 | } 15 | if (config.width) { 16 | newSquare.area = newSquare.area * config.width; 17 | } 18 | return newSquare; 19 | } 20 | //--createSquare返回的对象是newSquare,所有只能获取color和area并获取不了width这个属性的值.. 21 | var mySquare1 = createSquare({ color: "red" }); //与接口的变量color一样,此时这个值是取出是默认值color=red 22 | var mySquare2 = createSquare({ color1: "red" }); //与接口的变量color不一样,此时这个值是取出是默认值color=white 23 | console.log(mySquare1.color + "==" + mySquare1.area); // 24 | console.log(mySquare2.color + "==" + mySquare2.area); // 25 | var mySquare3 = createSquare({ color: "yellow", width: 80 }); //这里给了两个变量值,一个是color,一个是width 26 | console.log(mySquare3.color + "==" + mySquare3.area); //所以这个值必须等于8000 27 | -------------------------------------------------------------------------------- /WebContent/Interfaces/test2.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Not all properties of an interface may be required. 3 | * Some exist under certain conditions or may not be there at all 4 | *并非需要一个接口的所有属性。在某些条件下的一些存在或可以不存在的。 5 | *这句话说的是:就算你SquareConfig接口定义的变量是color,到调用createSquare的时候你给color1变量照样可以取出z值来 6 | *这个值只不过是:默认的newSquare的white值,如果是一样的color变量他就会取出你给赋格对象的color(red) 7 | */ 8 | 9 | 10 | interface SquareConfig { 11 | color?: string; 12 | width?: number; 13 | } 14 | /***************创建一个对象function.**************/ 15 | function createSquare(config: SquareConfig): {color: string; area: number} { 16 | //此时newSquare里面的参数必须与 :后面里面的参数名称一致. 17 | var newSquare = {color: "white", area: 100}; 18 | 19 | if (config.color) { 20 | newSquare.color = config.color; 21 | } 22 | if (config.width) { 23 | newSquare.area = newSquare.area * config.width; 24 | } 25 | return newSquare; 26 | } 27 | 28 | 29 | //--createSquare返回的对象是newSquare,所有只能获取color和area并获取不了width这个属性的值.. 30 | 31 | var mySquare1 = createSquare({color: "red"});//与接口的变量color一样,此时这个值是取出是默认值color=red 32 | var mySquare2 = createSquare({color1: "red"});//与接口的变量color不一样,此时这个值是取出是默认值color=white 33 | console.log(mySquare1.color+"=="+mySquare1.area);// 34 | console.log(mySquare2.color+"=="+mySquare2.area);// 35 | 36 | var mySquare3 = createSquare({color: "yellow",width:80});//这里给了两个变量值,一个是color,一个是width 37 | console.log(mySquare3.color+"=="+mySquare3.area);//所以这个值必须等于8000 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /WebContent/Interfaces/test3.js: -------------------------------------------------------------------------------- 1 | //--typescript的function类型结合javascript的search函数使用 2 | var mySearch; //声明一个interface变量接收 3 | mySearch = function (source, subString) { 4 | var result = source.search(subString); 5 | if (result == -1) { 6 | return false; 7 | } 8 | else { 9 | return true; 10 | } 11 | }; 12 | $(function () { 13 | var source = "this is ok"; 14 | var subString1 = "ok"; 15 | var subString2 = "not"; 16 | var result; 17 | var result1 = mySearch(source, subString1); //从source字符串上面找ok,返回值是true 18 | var result2 = mySearch(source, subString2); //从source字符串上面找not,返回值是false 19 | alert(result1); // 20 | alert(result2); 21 | }); 22 | -------------------------------------------------------------------------------- /WebContent/Interfaces/test3.ts: -------------------------------------------------------------------------------- 1 | 2 | //--typescript的function类型结合javascript的search函数使用 3 | 4 | interface searchFunt{ 5 | //声明一个两个变量.. 6 | (source: string, subString: string): boolean; 7 | } 8 | 9 | var mySearch : searchFunt;//声明一个interface变量接收 10 | mySearch = function(source:string,subString:string){ 11 | var result = source.search(subString); 12 | if (result == -1) { 13 | return false; 14 | } 15 | else { 16 | return true; 17 | } 18 | } 19 | 20 | $(function(){ 21 | var source:string ="this is ok"; 22 | var subString1:string ="ok"; 23 | var subString2:string ="not"; 24 | var result:boolean; 25 | 26 | var result1= mySearch(source,subString1);//从source字符串上面找ok,返回值是true 27 | var result2= mySearch(source,subString2);//从source字符串上面找not,返回值是false 28 | alert(result1);// 29 | alert(result2); 30 | }); 31 | 32 | -------------------------------------------------------------------------------- /WebContent/Interfaces/test4.js: -------------------------------------------------------------------------------- 1 | /// 2 | //Array Types 3 | var myArray; 4 | myArray = ["Bob", "Fred"]; 5 | $(function () { 6 | $.each(myArray, function (key, val) { 7 | alert(val); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /WebContent/Interfaces/test4.ts: -------------------------------------------------------------------------------- 1 | /// 2 | //Array Types 3 | 4 | interface StringArray { 5 | [index: number]: string; 6 | //length: number; 7 | } 8 | var myArray:StringArray; 9 | 10 | myArray = ["Bob", "Fred"]; 11 | 12 | 13 | $(function(){ 14 | $.each(myArray,function(key,val){ 15 | alert(val); 16 | }); 17 | }); 18 | 19 | -------------------------------------------------------------------------------- /WebContent/Interfaces/test5.js: -------------------------------------------------------------------------------- 1 | /// 2 | //--实现IClock接口 3 | var Clock = (function () { 4 | function Clock(h, m) { 5 | } //--构造函数方法 6 | Clock.prototype.setTime = function (d) { 7 | this.currentTime = d; 8 | }; 9 | return Clock; 10 | })(); 11 | var Clock1 = (function () { 12 | function Clock1(h, m) { 13 | } 14 | return Clock1; 15 | })(); 16 | var cs = Clock1; 17 | var newClock = new cs(7, 30); 18 | console.log(newClock); 19 | -------------------------------------------------------------------------------- /WebContent/Interfaces/test5.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | //Class Types(implements) 4 | 5 | interface IClock { 6 | currentTime: Date; 7 | setTime(d: Date); 8 | } 9 | 10 | //--实现IClock接口 11 | class Clock implements IClock{ 12 | 13 | currentTime:Date; 14 | constructor(h: number, m: number) { }//--构造函数方法 15 | setTime(d:Date){ 16 | this.currentTime=d; 17 | } 18 | } 19 | //-------------------------------------------------- 20 | interface IClock1 { 21 | new (hour: number, minute: number); 22 | } 23 | class Clock1 { 24 | currentTime: Date; 25 | constructor(h: number, m: number) { } 26 | } 27 | 28 | var cs: IClock1 = Clock1; 29 | var newClock = new cs(7, 30); 30 | 31 | console.log(newClock); 32 | 33 | -------------------------------------------------------------------------------- /WebContent/Interfaces/test6.js: -------------------------------------------------------------------------------- 1 | /// 2 | //---赋值.. 3 | var square = {}; 4 | square.color = "red"; 5 | square.sideLength = 100; 6 | square.penWidth = 50; 7 | -------------------------------------------------------------------------------- /WebContent/Interfaces/test6.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | //Extending Interfaces 4 | interface IShape{ 5 | color:string; 6 | 7 | } 8 | interface PenStroke { 9 | penWidth: number; 10 | } 11 | //--接口继承接口,用,分割开多继承. 12 | interface ISquare extends IShape,PenStroke { 13 | sideLength: number; 14 | } 15 | 16 | //---赋值.. 17 | var square = {}; 18 | 19 | square.color="red"; 20 | square.sideLength=100; 21 | square.penWidth=50; 22 | 23 | 24 | -------------------------------------------------------------------------------- /WebContent/Interfaces/test7.js: -------------------------------------------------------------------------------- 1 | /// 2 | var c; 3 | c(10); //开始. 4 | c.interval = 5.0; 5 | c.reset(); //重置. 6 | -------------------------------------------------------------------------------- /WebContent/Interfaces/test7.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | //Hybrid Types(混合型) 4 | 5 | 6 | //--计算器 7 | interface Counter { 8 | (start: number): string;//声明一个开始变量 9 | interval:number;//声明一个间隔变量 10 | reset(): void;//声明一个重置function方法 11 | } 12 | 13 | var c: Counter; 14 | 15 | c(10);//开始. 16 | 17 | c.interval=5.0; 18 | 19 | c.reset();//重置. 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /WebContent/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /WebContent/Merging/html/test1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 |

11 |
12 | 13 | -------------------------------------------------------------------------------- /WebContent/Merging/test-1.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Merging Interfaces 3 | * 合并接口.. 4 | */ 5 | var box = { height: 5, width: 6, scale: 10 }; 6 | -------------------------------------------------------------------------------- /WebContent/Merging/test-1.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Merging Interfaces 3 | * 合并接口.. 4 | */ 5 | 6 | /** 7 | * 最简单的,也许是最常见的,类型声明合并是合并接口。将两个相同的接口合并在一块. 8 | */ 9 | 10 | interface Box { 11 | height: number; 12 | width: number; 13 | } 14 | 15 | interface Box { 16 | scale: number; 17 | } 18 | 19 | var box: Box = {height: 5, width: 6, scale: 10}; 20 | 21 | 22 | 23 | interface Document { 24 | createElement(tagName: any): Element; 25 | } 26 | interface Document { 27 | createElement(tagName: string): HTMLElement; 28 | } 29 | interface Document { 30 | createElement(tagName: "div"): HTMLDivElement; 31 | createElement(tagName: "span"): HTMLSpanElement; 32 | createElement(tagName: "canvas"): HTMLCanvasElement; 33 | } 34 | 35 | 36 | interface Document { 37 | createElement(tagName: "div"): HTMLDivElement; 38 | createElement(tagName: "span"): HTMLSpanElement; 39 | createElement(tagName: "canvas"): HTMLCanvasElement; 40 | createElement(tagName: string): HTMLElement; 41 | createElement(tagName: any): Element; 42 | } -------------------------------------------------------------------------------- /WebContent/Merging/test-2.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Merging Modules 3 | * 合并块. 4 | *要合并的价值,在每一个网站的声明,如果一个模块已经给定名称存在,它进一步采取现有的模块 5 | *并添加第二个模块第一的出口成员扩展。 6 | */ 7 | var MAnimals; 8 | (function (MAnimals) { 9 | var Zebra = (function () { 10 | function Zebra() { 11 | } 12 | return Zebra; 13 | })(); 14 | MAnimals.Zebra = Zebra; 15 | })(MAnimals || (MAnimals = {})); 16 | var MAnimals; 17 | (function (MAnimals) { 18 | var Dog = (function () { 19 | function Dog() { 20 | } 21 | return Dog; 22 | })(); 23 | MAnimals.Dog = Dog; 24 | })(MAnimals || (MAnimals = {})); 25 | //---这个MYAnimals块等同上面两个module 26 | var MYAnimals; 27 | (function (MYAnimals) { 28 | var Zebra = (function () { 29 | function Zebra() { 30 | } 31 | return Zebra; 32 | })(); 33 | MYAnimals.Zebra = Zebra; 34 | var Dog = (function () { 35 | function Dog() { 36 | } 37 | return Dog; 38 | })(); 39 | MYAnimals.Dog = Dog; 40 | })(MYAnimals || (MYAnimals = {})); 41 | /** 42 | * 模块合并的这种模式是一个有用的起点,但要得到我们还需要了解同非成员国导出会发生什么更完整的场景画面。 43 | * 非导出成员只有原来的(未合并)模块中可见,这意味着合并后,合并的成员,来自其他声明无法看到非成员导出 44 | */ 45 | var myAnimal; 46 | (function (myAnimal) { 47 | var haveMuscles = true; 48 | function animalsHaveMuscles() { 49 | return haveMuscles; 50 | } 51 | myAnimal.animalsHaveMuscles = animalsHaveMuscles; 52 | })(myAnimal || (myAnimal = {})); 53 | var myAnimal; 54 | (function (myAnimal) { 55 | function doAnimalsHaveMuscles() { 56 | //return haveMuscles; // 这里这个值是不可以返回. 57 | } 58 | myAnimal.doAnimalsHaveMuscles = doAnimalsHaveMuscles; 59 | })(myAnimal || (myAnimal = {})); 60 | /** 61 | * Merging Modules with Classes, Functions, and Enums 62 | * 合并模块与类,函数和枚举 63 | * 64 | * 模块具有足够的灵活性,以也与其它类型的声明合并。要做到这一点,该模块声明必须遵循的声明,将与合并。 65 | * 由此产生的声明有两种申报类型的属性。在typescript使用这个性能来模拟一些在JavaScript模式以及其它的编程语言 66 | */ 67 | var Album = (function () { 68 | function Album() { 69 | } 70 | return Album; 71 | })(); 72 | var Album; 73 | (function (Album) { 74 | var AlbumLabel = (function () { 75 | function AlbumLabel() { 76 | } 77 | return AlbumLabel; 78 | })(); 79 | Album.AlbumLabel = AlbumLabel; 80 | })(Album || (Album = {})); 81 | -------------------------------------------------------------------------------- /WebContent/Merging/test-2.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Merging Modules 3 | * 合并块. 4 | *要合并的价值,在每一个网站的声明,如果一个模块已经给定名称存在,它进一步采取现有的模块 5 | *并添加第二个模块第一的出口成员扩展。 6 | */ 7 | module MAnimals { 8 | export class Zebra { } 9 | } 10 | 11 | module MAnimals { 12 | export interface Legged { numberOfLegs: number; } 13 | export class Dog { } 14 | } 15 | 16 | 17 | //---这个MYAnimals块等同上面两个module 18 | module MYAnimals { 19 | export interface Legged { numberOfLegs: number; } 20 | 21 | export class Zebra { } 22 | export class Dog { } 23 | } 24 | 25 | 26 | /** 27 | * 模块合并的这种模式是一个有用的起点,但要得到我们还需要了解同非成员国导出会发生什么更完整的场景画面。 28 | * 非导出成员只有原来的(未合并)模块中可见,这意味着合并后,合并的成员,来自其他声明无法看到非成员导出 29 | */ 30 | 31 | 32 | module myAnimal { 33 | var haveMuscles = true; 34 | 35 | export function animalsHaveMuscles() { 36 | return haveMuscles; 37 | } 38 | } 39 | 40 | module myAnimal { 41 | export function doAnimalsHaveMuscles() { 42 | //return haveMuscles; // 这里这个值是不可以返回. 43 | } 44 | } 45 | 46 | 47 | /** 48 | * Merging Modules with Classes, Functions, and Enums 49 | * 合并模块与类,函数和枚举 50 | * 51 | * 模块具有足够的灵活性,以也与其它类型的声明合并。要做到这一点,该模块声明必须遵循的声明,将与合并。 52 | * 由此产生的声明有两种申报类型的属性。在typescript使用这个性能来模拟一些在JavaScript模式以及其它的编程语言 53 | */ 54 | class Album { 55 | label: Album.AlbumLabel; 56 | } 57 | module Album { 58 | export class AlbumLabel { } 59 | } 60 | -------------------------------------------------------------------------------- /WebContent/Mixins/html/test1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /WebContent/Mixins/test-1.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Mixin使用. 3 | * 4 | *随着传统的面向对象的层次结构,从可重用的组件建立类的另一种流行的方式是通过简单的组合部分类来构建他们。 5 | *你可能熟悉混入或性状比如Scala语言的理念,模式也达到了JavaScript的一些社区人气 6 | */ 7 | // Disposable Mixin(一次性) 8 | var Disposable = (function () { 9 | function Disposable() { 10 | } 11 | Disposable.prototype.dispose = function () { 12 | this.isDisposed = true; 13 | }; 14 | return Disposable; 15 | })(); 16 | // Activatable Mixin(激活混入) 17 | var Activatable = (function () { 18 | function Activatable() { 19 | } 20 | Activatable.prototype.activate = function () { 21 | this.isActive = true; 22 | }; 23 | Activatable.prototype.deactivate = function () { 24 | this.isActive = false; 25 | }; 26 | return Activatable; 27 | })(); 28 | //SmartObject类实现Disposable与Activatable类 29 | var SmartObject = (function () { 30 | function SmartObject() { 31 | var _this = this; 32 | // Disposable 33 | this.isDisposed = false; 34 | // Activatable 35 | this.isActive = false; 36 | setInterval(function () { return console.log(_this.isActive + " : " + _this.isDisposed); }, 500); 37 | } 38 | //相互作用 39 | SmartObject.prototype.interact = function () { 40 | this.activate(); 41 | }; 42 | return SmartObject; 43 | })(); 44 | applyMixins(SmartObject, [Disposable, Activatable]); 45 | var smartObj = new SmartObject(); 46 | setTimeout(function () { return smartObj.interact(); }, 1000); 47 | //////////////////////////////////////// 48 | // In your runtime library somewhere 49 | //在您的运行时库的地方 50 | //////////////////////////////////////// 51 | function applyMixins(derivedCtor, baseCtors) { 52 | baseCtors.forEach(function (baseCtor) { 53 | Object.getOwnPropertyNames(baseCtor.prototype).forEach(function (name) { 54 | derivedCtor.prototype[name] = baseCtor.prototype[name]; 55 | }); 56 | }); 57 | } 58 | -------------------------------------------------------------------------------- /WebContent/Mixins/test-1.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Mixin使用. 3 | * 4 | *随着传统的面向对象的层次结构,从可重用的组件建立类的另一种流行的方式是通过简单的组合部分类来构建他们。 5 | *你可能熟悉混入或性状比如Scala语言的理念,模式也达到了JavaScript的一些社区人气 6 | */ 7 | 8 | // Disposable Mixin(一次性) 9 | class Disposable { 10 | isDisposed: boolean; 11 | dispose() { 12 | this.isDisposed = true; 13 | } 14 | 15 | } 16 | 17 | // Activatable Mixin(激活混入) 18 | class Activatable { 19 | isActive: boolean; 20 | activate() { 21 | this.isActive = true; 22 | } 23 | deactivate() { 24 | this.isActive = false; 25 | } 26 | } 27 | 28 | //SmartObject类实现Disposable与Activatable类 29 | class SmartObject implements Disposable, Activatable { 30 | constructor() { 31 | setInterval(() => console.log(this.isActive + " : " + this.isDisposed), 500); 32 | } 33 | 34 | //相互作用 35 | interact() { 36 | this.activate(); 37 | } 38 | 39 | // Disposable 40 | isDisposed: boolean = false; 41 | dispose: () => void; 42 | // Activatable 43 | isActive: boolean = false; 44 | activate: () => void; 45 | deactivate: () => void; 46 | } 47 | applyMixins(SmartObject, [Disposable, Activatable]) 48 | 49 | var smartObj = new SmartObject(); 50 | setTimeout(() => smartObj.interact(), 1000); 51 | 52 | //////////////////////////////////////// 53 | // In your runtime library somewhere 54 | //在您的运行时库的地方 55 | //////////////////////////////////////// 56 | 57 | function applyMixins(derivedCtor: any, baseCtors: any[]) { 58 | baseCtors.forEach(baseCtor => { 59 | Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => { 60 | derivedCtor.prototype[name] = baseCtor.prototype[name]; 61 | }) 62 | }); 63 | } -------------------------------------------------------------------------------- /WebContent/Modules/html/test1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |
16 | 17 | -------------------------------------------------------------------------------- /WebContent/Modules/html/test2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 | 11 |
12 |
13 |
14 | 15 | -------------------------------------------------------------------------------- /WebContent/Modules/html/test3.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |
16 | 17 | -------------------------------------------------------------------------------- /WebContent/Modules/html/test4.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |
16 | 17 | -------------------------------------------------------------------------------- /WebContent/Modules/html/test5.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 | 11 |
12 |
13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /WebContent/Modules/html/test6.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Insert title here 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 |
14 |
15 | 16 | 17 | -------------------------------------------------------------------------------- /WebContent/Modules/test-1.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | /*** 6 | * Splitting Across Files分割跨文件 7 | */ 8 | // 声明一个数组. 9 | var strings = ['Hello', '98052', '101']; 10 | // 使用这个验证. 11 | var validators = {}; 12 | validators['Zip Code'] = new Validation.ZipCodeValidator(); //这个是验证邮政编码 13 | validators['Letters only'] = new Validation.LettersOnlyValidator(); //这个是验证英文 14 | function showMsg() { 15 | //显示每个字符串是否通过每个验证 16 | strings.forEach(function (s) { 17 | for (var name in validators) { 18 | console.log('"' + s + '" ' + (validators[name].isAcceptable(s) ? ' matches ' : ' does not match ') + name); 19 | $("#msg1").html('"' + s + '" ' + (validators[name].isAcceptable(s) ? ' matches ' : ' does not match ') + name); 20 | } //--for--end 21 | }); //--forEach--end 22 | } 23 | $(document).ready(function () { 24 | showMsg(); 25 | }); 26 | -------------------------------------------------------------------------------- /WebContent/Modules/test-1.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | /// 4 | /// 5 | 6 | /*** 7 | * Splitting Across Files分割跨文件 8 | */ 9 | 10 | // 声明一个数组. 11 | var strings = ['Hello', '98052', '101']; 12 | 13 | // 使用这个验证. 14 | var validators: { [s: string]: Validation.StringValidator; } = {}; 15 | 16 | validators['Zip Code'] = new Validation.ZipCodeValidator();//这个是验证邮政编码 17 | validators['Letters only'] = new Validation.LettersOnlyValidator();//这个是验证英文 18 | 19 | 20 | function showMsg():void{ 21 | 22 | //显示每个字符串是否通过每个验证 23 | strings.forEach(s => { 24 | for (var name in validators) { 25 | 26 | console.log('"' + s + '" ' + (validators[name].isAcceptable(s) ? ' matches ' : ' does not match ') + name); 27 | $("#msg1").html('"' + s + '" ' + (validators[name].isAcceptable(s) ? ' matches ' : ' does not match ') + name); 28 | }//--for--end 29 | 30 | });//--forEach--end 31 | 32 | } 33 | 34 | 35 | $(document).ready(function(){ 36 | showMsg(); 37 | 38 | 39 | }); 40 | -------------------------------------------------------------------------------- /WebContent/Modules/test-2.js: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | var strs = ["13697811800", "jilongliang@sina.com"]; 4 | var validators1 = {}; 5 | validators1["Tel"] = new ValidationUtils.TelValidator; //验证码QQ 6 | validators1["Email"] = new ValidationUtils.EmailValidator; //验证Email 7 | //-------显示信息1---------------------------- 8 | function showMsg1() { 9 | strs.forEach(function (s) { 10 | for (var name in validators1) { 11 | console.log('"' + s + '" ' + (validators1[name].isAcceptable(s) ? ' 匹配 ' : ' 不匹配 ') + name); 12 | } 13 | }); 14 | } 15 | //-------------------显示信息2--------------------- 16 | function showMsg2() { 17 | //--方法一--- 18 | var telObj; 19 | telObj = new ValidationUtils.TelValidator; 20 | //--方法二--- 21 | //var telObj=new ValidationUtils.TelValidator; 22 | var tel = "13697811809"; 23 | var flag = telObj.isAcceptable(tel); //调用TelValidator类的isAcceptable方法 24 | console.log(flag ? tel + " 匹配 " : tel + "\t 不匹配 "); 25 | $("#msg2").html(flag ? "" + tel + " 匹配 " : "" + tel + "\t 不匹配"); 26 | } 27 | $(function () { 28 | showMsg1(); 29 | showMsg2(); 30 | }); 31 | -------------------------------------------------------------------------------- /WebContent/Modules/test-2.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | 5 | var strs : Array =["13697811800","jilongliang@sina.com"]; 6 | 7 | var validators1: { [s: string]: ValidationUtils.StringValidator; } = {}; 8 | 9 | validators1["Tel"]=new ValidationUtils.TelValidator;//验证码QQ 10 | 11 | validators1["Email"] = new ValidationUtils.EmailValidator;//验证Email 12 | 13 | //-------显示信息1---------------------------- 14 | function showMsg1():void{ 15 | strs.forEach 16 | (s=> 17 | { 18 | for(var name in validators1 ){ 19 | console.log('"' + s + '" ' + (validators1[name].isAcceptable(s) ? ' 匹配 ' : ' 不匹配 ') + name); 20 | } 21 | } 22 | ); 23 | } 24 | 25 | //-------------------显示信息2--------------------- 26 | function showMsg2():void{ 27 | 28 | //--方法一--- 29 | var telObj:ValidationUtils.TelValidator; 30 | 31 | telObj=new ValidationUtils.TelValidator; 32 | 33 | //--方法二--- 34 | //var telObj=new ValidationUtils.TelValidator; 35 | 36 | var tel : string="13697811809"; 37 | var flag : boolean=telObj.isAcceptable(tel);//调用TelValidator类的isAcceptable方法 38 | 39 | console.log(flag? tel+" 匹配 " : tel+"\t 不匹配 "); 40 | 41 | $("#msg2").html(flag? ""+tel+" 匹配 " : ""+tel+"\t 不匹配"); 42 | 43 | } 44 | 45 | 46 | 47 | $(function(){ 48 | showMsg1(); 49 | 50 | showMsg2(); 51 | }); 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /WebContent/Modules/test-3.js: -------------------------------------------------------------------------------- 1 | /// 2 | define(["require", "exports", 'test3/TelValidator', 'test3/EmailValidator'], function (require, exports, telValidator, emailValidator) { 3 | //-------------------显示信息1--------------------- 4 | function showMsgs1() { 5 | //--方法一--- 6 | var telObj = new emailValidator.EmailValidator(); // 7 | var tel = "13697811809"; 8 | var flag = telObj.isAcceptable(tel); //调用TelValidator类的isAcceptable方法 9 | console.log(flag ? tel + " 匹配 " : tel + "\t 不匹配 "); 10 | $("#msg1").html(flag ? "" + tel + " 匹配 " : "" + tel + "\t 不匹配"); 11 | } 12 | $(function () { 13 | //showMsgs1(); 14 | var strings = ['13697811809', 'jilongliang@sina.com']; 15 | var validators = {}; 16 | validators['email'] = new emailValidator.EmailValidator(); 17 | validators['tel'] = new telValidator.TelValidator(); 18 | strings.forEach(function (s) { 19 | for (var name in validators) { 20 | console.log('"' + s + '" ' + (validators[name].isAcceptable(s) ? ' matches ' : ' does not match ') + name); 21 | } 22 | }); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /WebContent/Modules/test-3.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | /*** 4 | * import与require关键字使用..require(是命令,要求的意思.) 5 | */ 6 | 7 | //引入ValidationUtils3.ts文件,前面这个是用了module块关键字定义ts文件,需要用reference与path引入. 8 | import validation = require('test3/ValidationUtils3'); 9 | import telValidator = require('test3/TelValidator'); 10 | import emailValidator = require('test3/EmailValidator'); 11 | 12 | //-------------------显示信息1--------------------- 13 | function showMsgs1() : void { 14 | //--方法一--- 15 | var telObj=new emailValidator.EmailValidator();// 16 | var tel : string="13697811809"; 17 | var flag : boolean=telObj.isAcceptable(tel);//调用TelValidator类的isAcceptable方法 18 | console.log(flag? tel+" 匹配 " : tel+"\t 不匹配 "); 19 | $("#msg1").html(flag? ""+tel+" 匹配 " : ""+tel+"\t 不匹配"); 20 | } 21 | 22 | 23 | $(function() { 24 | //showMsgs1(); 25 | var strings = ['13697811809', 'jilongliang@sina.com']; 26 | var validators: { [s: string]: validation.StringValidator; } = {}; 27 | validators['email'] =new emailValidator.EmailValidator(); 28 | validators['tel'] = new telValidator.TelValidator(); 29 | 30 | strings.forEach(s => { 31 | for (var name in validators) { 32 | console.log('"' + s + '" ' + (validators[name].isAcceptable(s) ? ' matches ' : ' does not match ') + name); 33 | } 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /WebContent/Modules/test-4.js: -------------------------------------------------------------------------------- 1 | /// 2 | define(["require", "exports", 'test4/TelValidator4'], function (require, exports, telValidator) { 3 | //-------------------显示信息1--------------------- 4 | function showMsgs1() { 5 | //--方法一--- 6 | var telObj = new telValidator(); // 7 | var tel = "13697811809"; 8 | var flag = telObj.isAcceptable(tel); //调用TelValidator类的isAcceptable方法 9 | console.log(flag ? tel + " 匹配 " : tel + "\t 不匹配 "); 10 | $("#msg1").html(flag ? "" + tel + " 匹配 " : "" + tel + "\t 不匹配"); 11 | } 12 | $(function () { 13 | showMsgs1(); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /WebContent/Modules/test-4.ts: -------------------------------------------------------------------------------- 1 | 2 | /// 3 | 4 | 5 | //引入ValidationUtils3.ts文件,前面这个是用了module块关键字定义ts文件,需要用reference与path引入. 6 | import validation = require('test4/ValidationUtils4'); 7 | import telValidator = require('test4/TelValidator4'); 8 | import emailValidator = require('test4/EmailValidator4'); 9 | 10 | 11 | //-------------------显示信息1--------------------- 12 | function showMsgs1() : void { 13 | 14 | //--方法一--- 15 | var telObj=new telValidator();// 16 | 17 | var tel : string="13697811809"; 18 | var flag : boolean=telObj.isAcceptable(tel);//调用TelValidator类的isAcceptable方法 19 | 20 | console.log(flag? tel+" 匹配 " : tel+"\t 不匹配 "); 21 | 22 | $("#msg1").html(flag? ""+tel+" 匹配 " : ""+tel+"\t 不匹配"); 23 | 24 | } 25 | 26 | 27 | $(function (){ 28 | 29 | showMsgs1(); 30 | }); -------------------------------------------------------------------------------- /WebContent/Modules/test-5.js: -------------------------------------------------------------------------------- 1 | //-------import入module 块 2 | var polygons = Shapes.Polygons; 3 | var tg = new polygons.Triangle("三角形面积是:"); 4 | var triangleArea = tg.getTriangleArea(3); //传一个3进去.. 5 | var sq = new polygons.Square("正方形面积是:"); 6 | var squareArea = sq.getSquareArea(8); 7 | $(function () { 8 | $("#msg1").html("" + triangleArea + ""); 9 | $("#msg2").html("" + squareArea + ""); 10 | }); 11 | -------------------------------------------------------------------------------- /WebContent/Modules/test-5.ts: -------------------------------------------------------------------------------- 1 | //-------import入module 块 2 | import polygons = Shapes.Polygons; 3 | 4 | var tg = new polygons.Triangle("三角形面积是:"); 5 | var triangleArea=tg.getTriangleArea(3);//传一个3进去.. 6 | 7 | 8 | var sq = new polygons.Square("正方形面积是:"); 9 | var squareArea = sq.getSquareArea(8); 10 | 11 | 12 | $(function () { 13 | 14 | $("#msg1").html(""+triangleArea+""); 15 | $("#msg2").html(""+squareArea+""); 16 | 17 | }) -------------------------------------------------------------------------------- /WebContent/Modules/test-6.js: -------------------------------------------------------------------------------- 1 | //引入node.d.ts文件 2 | /// 3 | define(["require", "exports", "url"], function (require, exports, url) { 4 | var myUrl = url.parse("http://www.typescriptlang.org"); 5 | $(function () { 6 | alert(myUrl); 7 | //$("#msg1").html(myUrl); 8 | }); 9 | }); 10 | -------------------------------------------------------------------------------- /WebContent/Modules/test-6.ts: -------------------------------------------------------------------------------- 1 | //引入node.d.ts文件 2 | /// 3 | 4 | import url = require("url"); 5 | 6 | var myUrl = url.parse("http://www.typescriptlang.org"); 7 | 8 | $(function() { 9 | 10 | alert(myUrl); 11 | //$("#msg1").html(myUrl); 12 | 13 | }); -------------------------------------------------------------------------------- /WebContent/Modules/test1/LettersOnlyValidator.js: -------------------------------------------------------------------------------- 1 | /// 2 | var Validation; 3 | (function (Validation) { 4 | //匹配A-Z,a-z的英文 5 | var lettersRegexp = /^[A-Za-z]+$/; 6 | var LettersOnlyValidator = (function () { 7 | function LettersOnlyValidator() { 8 | } 9 | LettersOnlyValidator.prototype.isAcceptable = function (s) { 10 | return lettersRegexp.test(s); 11 | }; 12 | return LettersOnlyValidator; 13 | })(); 14 | Validation.LettersOnlyValidator = LettersOnlyValidator; 15 | })(Validation || (Validation = {})); 16 | -------------------------------------------------------------------------------- /WebContent/Modules/test1/LettersOnlyValidator.ts: -------------------------------------------------------------------------------- 1 | /// 2 | 3 | 4 | module Validation { 5 | //匹配A-Z,a-z的英文 6 | var lettersRegexp = /^[A-Za-z]+$/; 7 | export class LettersOnlyValidator implements StringValidator { 8 | isAcceptable(s: string) { 9 | return lettersRegexp.test(s); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /WebContent/Modules/test1/Validation.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jilongliang/TypeScript/a3852bfb426d5e3d009fcad7e20585159142938c/WebContent/Modules/test1/Validation.js -------------------------------------------------------------------------------- /WebContent/Modules/test1/Validation.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | module Validation{ 4 | export interface StringValidator { 5 | isAcceptable(s: string): boolean;//是否接受. 6 | } 7 | } -------------------------------------------------------------------------------- /WebContent/Modules/test1/ZipCodeValidator.js: -------------------------------------------------------------------------------- 1 | /// 2 | var Validation; 3 | (function (Validation) { 4 | //匹配0-9的数字. 5 | var numberRegexp = /^[0-9]+$/; 6 | var ZipCodeValidator = (function () { 7 | function ZipCodeValidator() { 8 | } 9 | ZipCodeValidator.prototype.isAcceptable = function (s) { 10 | //如果长度=5并且是数字就返回一个true 11 | return s.length === 5 && numberRegexp.test(s); 12 | }; 13 | return ZipCodeValidator; 14 | })(); 15 | Validation.ZipCodeValidator = ZipCodeValidator; 16 | })(Validation || (Validation = {})); 17 | -------------------------------------------------------------------------------- /WebContent/Modules/test1/ZipCodeValidator.ts: -------------------------------------------------------------------------------- 1 | /// 2 | module Validation { 3 | //匹配0-9的数字. 4 | var numberRegexp = /^[0-9]+$/; 5 | 6 | export class ZipCodeValidator implements StringValidator { 7 | isAcceptable(s: string) { 8 | //如果长度=5并且是数字就返回一个true 9 | return s.length === 5 && numberRegexp.test(s); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /WebContent/Modules/test2/ValidationUtils.js: -------------------------------------------------------------------------------- 1 | /** 2 | *声明一个ValidationUtils工具块module 3 | *推荐使用. 4 | */ 5 | var ValidationUtils; 6 | (function (ValidationUtils) { 7 | // 匹配email正则表达式 8 | var emailReg = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/; 9 | var EmailValidator = (function () { 10 | function EmailValidator() { 11 | } 12 | EmailValidator.prototype.isAcceptable = function (s) { 13 | return emailReg.test(s); 14 | }; 15 | return EmailValidator; 16 | })(); 17 | ValidationUtils.EmailValidator = EmailValidator; 18 | //匹配移动电话号码 19 | var telReg = /^(13[0-9]|15[0-9]|18[0-9])\d{8}$/; 20 | var TelValidator = (function () { 21 | function TelValidator() { 22 | } 23 | TelValidator.prototype.isAcceptable = function (s) { 24 | return telReg.test(s); 25 | }; 26 | return TelValidator; 27 | })(); 28 | ValidationUtils.TelValidator = TelValidator; 29 | })(ValidationUtils || (ValidationUtils = {})); 30 | -------------------------------------------------------------------------------- /WebContent/Modules/test2/ValidationUtils.ts: -------------------------------------------------------------------------------- 1 | /** 2 | *声明一个ValidationUtils工具块module 3 | *推荐使用. 4 | */ 5 | module ValidationUtils{ 6 | 7 | //-声明StringValidator字符串验证器. 8 | export interface StringValidator { 9 | isAcceptable(str: string): boolean;//是否接受. 10 | } 11 | 12 | // 匹配email正则表达式 13 | var emailReg = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/; 14 | export class EmailValidator implements StringValidator { 15 | isAcceptable(s: string) { 16 | return emailReg.test(s); 17 | } 18 | } 19 | 20 | //匹配移动电话号码 21 | var telReg=/^(13[0-9]|15[0-9]|18[0-9])\d{8}$/; 22 | 23 | export class TelValidator implements StringValidator{ 24 | isAcceptable(s:string){ 25 | return telReg.test(s); 26 | } 27 | } 28 | 29 | } -------------------------------------------------------------------------------- /WebContent/Modules/test3/EmailValidator.js: -------------------------------------------------------------------------------- 1 | /**import、require、export关键的使用..***********/ 2 | define(["require", "exports"], function (require, exports) { 3 | // 匹配email正则表达式 4 | var emailReg = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/; 5 | var EmailValidator = (function () { 6 | function EmailValidator() { 7 | } 8 | EmailValidator.prototype.isAcceptable = function (s) { 9 | return emailReg.test(s); 10 | }; 11 | return EmailValidator; 12 | })(); 13 | exports.EmailValidator = EmailValidator; 14 | }); 15 | -------------------------------------------------------------------------------- /WebContent/Modules/test3/EmailValidator.ts: -------------------------------------------------------------------------------- 1 | /**import、require、export关键的使用..***********/ 2 | 3 | //--导入--ValidationUtils3.ts文件--- 4 | import validation = require('./ValidationUtils3'); 5 | 6 | // 匹配email正则表达式 7 | var emailReg = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/; 8 | export class EmailValidator implements validation.StringValidator { 9 | isAcceptable(s: string) { 10 | return emailReg.test(s); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /WebContent/Modules/test3/TelValidator.js: -------------------------------------------------------------------------------- 1 | /**import、require、export关键的使用..***********/ 2 | define(["require", "exports"], function (require, exports) { 3 | //匹配移动电话号码 4 | var telReg = /^(13[0-9]|15[0-9]|18[0-9])\d{8}$/; 5 | var TelValidator = (function () { 6 | function TelValidator() { 7 | } 8 | TelValidator.prototype.isAcceptable = function (s) { 9 | return telReg.test(s); 10 | }; 11 | return TelValidator; 12 | })(); 13 | exports.TelValidator = TelValidator; 14 | }); 15 | -------------------------------------------------------------------------------- /WebContent/Modules/test3/TelValidator.ts: -------------------------------------------------------------------------------- 1 | /**import、require、export关键的使用..***********/ 2 | 3 | //--导入--ValidationUtils3.ts文件--- 4 | import validation = require('./ValidationUtils3'); 5 | 6 | //匹配移动电话号码 7 | var telReg=/^(13[0-9]|15[0-9]|18[0-9])\d{8}$/; 8 | 9 | export class TelValidator implements validation.StringValidator{ 10 | isAcceptable(s:string){ 11 | return telReg.test(s); 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /WebContent/Modules/test3/ValidationUtils3.js: -------------------------------------------------------------------------------- 1 | /* 这个ts没module关键字*/ 2 | define(["require", "exports"], function (require, exports) { 3 | }); 4 | -------------------------------------------------------------------------------- /WebContent/Modules/test3/ValidationUtils3.ts: -------------------------------------------------------------------------------- 1 | /* 这个ts没module关键字*/ 2 | 3 | export interface StringValidator { 4 | isAcceptable(s: string): boolean; 5 | } -------------------------------------------------------------------------------- /WebContent/Modules/test4/EmailValidator4.js: -------------------------------------------------------------------------------- 1 | /**export = 对象 的使用*/ 2 | define(["require", "exports"], function (require, exports) { 3 | // 匹配email正则表达式 4 | var emailReg = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/; 5 | var EmailValidator4 = (function () { 6 | function EmailValidator4() { 7 | } 8 | EmailValidator4.prototype.isAcceptable = function (s) { 9 | return emailReg.test(s); 10 | }; 11 | return EmailValidator4; 12 | })(); 13 | return EmailValidator4; 14 | }); 15 | -------------------------------------------------------------------------------- /WebContent/Modules/test4/EmailValidator4.ts: -------------------------------------------------------------------------------- 1 | /**export = 对象 的使用*/ 2 | 3 | import validation = require('./ValidationUtils4'); 4 | 5 | // 匹配email正则表达式 6 | var emailReg = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/; 7 | class EmailValidator4 implements validation.StringValidator { 8 | isAcceptable(s: string) { 9 | 10 | return emailReg.test(s); 11 | } 12 | } 13 | export = EmailValidator4; -------------------------------------------------------------------------------- /WebContent/Modules/test4/TelValidator4.js: -------------------------------------------------------------------------------- 1 | /**export = 对象 的使用*/ 2 | define(["require", "exports"], function (require, exports) { 3 | //匹配移动电话号码 4 | var telReg = /^(13[0-9]|15[0-9]|18[0-9])\d{8}$/; 5 | var TelValidator4 = (function () { 6 | function TelValidator4() { 7 | } 8 | TelValidator4.prototype.isAcceptable = function (s) { 9 | return telReg.test(s); 10 | }; 11 | return TelValidator4; 12 | })(); 13 | return TelValidator4; 14 | }); 15 | -------------------------------------------------------------------------------- /WebContent/Modules/test4/TelValidator4.ts: -------------------------------------------------------------------------------- 1 | /**export = 对象 的使用*/ 2 | 3 | 4 | import validation = require('./ValidationUtils4'); 5 | 6 | //匹配移动电话号码 7 | var telReg=/^(13[0-9]|15[0-9]|18[0-9])\d{8}$/; 8 | 9 | class TelValidator4 implements validation.StringValidator{ 10 | isAcceptable(s:string){ 11 | return telReg.test(s); 12 | } 13 | } 14 | 15 | export = TelValidator4;// -------------------------------------------------------------------------------- /WebContent/Modules/test4/ValidationUtils4.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 不使用Module,如果我们在typescript使用了module函数,则生成的代码在浏览器端执行时,需要有一些script loader的支持。 3 | * 对于浏览器端代码,我们一般生成amd风格的代码,所以需要找一个支持amd的库放在前端。这样的库有很多 4 | */ 5 | define(["require", "exports"], function (require, exports) { 6 | }); 7 | -------------------------------------------------------------------------------- /WebContent/Modules/test4/ValidationUtils4.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * 不使用Module,如果我们在typescript使用了module函数,则生成的代码在浏览器端执行时,需要有一些script loader的支持。 3 | * 对于浏览器端代码,我们一般生成amd风格的代码,所以需要找一个支持amd的库放在前端。这样的库有很多 4 | */ 5 | 6 | export interface StringValidator { 7 | isAcceptable(s: string): boolean; 8 | } -------------------------------------------------------------------------------- /WebContent/Modules/test5/Aliasing.js: -------------------------------------------------------------------------------- 1 | //------------别名的使用.. 2 | //--声明一个--Shapes块别名-- 3 | var Shapes; 4 | (function (Shapes) { 5 | //===========================多边形=========================== 6 | var Polygons; 7 | (function (Polygons) { 8 | //===========================三角形=========================== 9 | var Triangle = (function () { 10 | //声明构造方法--传一个名字的参数.. 11 | function Triangle(strName) { 12 | this.side = 3; //声明边一个变量,并且给一个默认值.. 13 | this.theName = strName; 14 | } 15 | //计算三角形,获取面积,这里为了返回一个构造方法的传进来的字符串,故返回类型给了一个any类型.. 16 | Triangle.prototype.getTriangleArea = function (side) { 17 | return this.theName + this.side * side; 18 | }; 19 | return Triangle; 20 | })(); 21 | Polygons.Triangle = Triangle; 22 | //===========================正方形=========================== 23 | var Square = (function () { 24 | //声明构造方法--传一个名字的参数.. 25 | function Square(strName) { 26 | this.side = 8; //声明边一个变量,并且给一个默认值.. 27 | this.theName = strName; 28 | } 29 | //---计算正方形,获取面积 30 | Square.prototype.getSquareArea = function (side) { 31 | return this.theName + this.side * side; 32 | }; 33 | return Square; 34 | })(); 35 | Polygons.Square = Square; 36 | })(Polygons = Shapes.Polygons || (Shapes.Polygons = {})); 37 | })(Shapes || (Shapes = {})); 38 | -------------------------------------------------------------------------------- /WebContent/Modules/test5/Aliasing.ts: -------------------------------------------------------------------------------- 1 | //------------别名的使用.. 2 | //--声明一个--Shapes块别名-- 3 | module Shapes { 4 | //===========================多边形=========================== 5 | export module Polygons { 6 | //===========================三角形=========================== 7 | export class Triangle { 8 | side : number = 3;//声明边一个变量,并且给一个默认值.. 9 | theName : string;//声明一个名字 10 | //声明构造方法--传一个名字的参数.. 11 | constructor(strName : string) { 12 | this.theName = strName; 13 | } 14 | //计算三角形,获取面积,这里为了返回一个构造方法的传进来的字符串,故返回类型给了一个any类型.. 15 | getTriangleArea(side : number) : any{ 16 | return this.theName+ this.side*side; 17 | } 18 | } 19 | //===========================正方形=========================== 20 | export class Square { 21 | side : number = 8;//声明边一个变量,并且给一个默认值.. 22 | theName : string;//声明一个名字 23 | //声明构造方法--传一个名字的参数.. 24 | constructor(strName : string) { 25 | this.theName = strName; 26 | } 27 | //---计算正方形,获取面积 28 | getSquareArea(side : number) : any{ 29 | return this.theName+ this.side*side; 30 | } 31 | } 32 | } 33 | } 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /WebContent/Modules/test6/D3.d.ts: -------------------------------------------------------------------------------- 1 | //环境内部模块 2 | 3 | declare module D3{ 4 | //声明一个Selectors选择器接口 5 | export interface Selectors { 6 | select: { 7 | (selector: string): Selection; 8 | (element: EventTarget): Selection; 9 | }; 10 | } 11 | //声明一个Event事件 12 | export interface Event { 13 | x: number; 14 | y: number; 15 | } 16 | //声明一个Base接口继承Selectors接口 17 | export interface Base extends Selectors { 18 | event: Event; 19 | } 20 | } 21 | 22 | 23 | declare var d3: D3.Base; -------------------------------------------------------------------------------- /WebContent/Modules/test6/node.d.ts: -------------------------------------------------------------------------------- 1 | //环境外部模块 2 | 3 | //在node.js中,大多数的任务是由加载一个或多个模块来实现的。我们可以定义自己的.d.ts文件 4 | //顶层出口报关单每个模块,但它更方便他们写为一个较大的.d.ts文件。要做到这一点,我们使用 5 | //了模块的引用名,这将提供给一个后来进口 6 | 7 | declare module "url" { 8 | export interface Url { 9 | protocol?: string; 10 | hostname?: string; 11 | pathname?: string; 12 | } 13 | 14 | export function parse(urlStr: string, parseQueryString?, slashesDenoteHost?): Url; 15 | } 16 | 17 | declare module "path" { 18 | export function normalize(p: string): string; 19 | export function join(...paths: any[]): string; 20 | export var sep: string; 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /WebContent/plugins/curl.js: -------------------------------------------------------------------------------- 1 | /** @license MIT License (c) copyright 2010-2013 B Cavalier & J Hann */ 2 | 3 | /** 4 | * curl (cujo resource loader) 5 | * An AMD-compliant javascript module and resource loader 6 | * 7 | * curl is part of the cujo.js family of libraries (http://cujojs.com/) 8 | * 9 | * Licensed under the MIT License at: 10 | * http://www.opensource.org/licenses/mit-license.php 11 | * 12 | */ 13 | (function (global) { 14 | //"use strict"; don't restore this until the config routine is refactored 15 | var 16 | version = '0.8.11', 17 | curlName = 'curl', 18 | defineName = 'define', 19 | bootScriptAttr = 'data-curl-run', 20 | bootScript, 21 | userCfg, 22 | prevCurl, 23 | prevDefine, 24 | doc = global.document, 25 | head = doc && (doc['head'] || doc.getElementsByTagName('head')[0]), 26 | // to keep IE from crying, we need to put scripts before any 27 | // elements, but after any . this should do it: 28 | insertBeforeEl = head && head.getElementsByTagName('base')[0] || null, 29 | // constants / flags 30 | msgUsingExports = {}, 31 | msgFactoryExecuted = {}, 32 | // this is the list of scripts that IE is loading. one of these will 33 | // be the "interactive" script. too bad IE doesn't send a readystatechange 34 | // event to tell us exactly which one. 35 | activeScripts = {}, 36 | // readyStates for IE6-9 37 | readyStates = 'addEventListener' in global ? {} : { 'loaded': 1, 'complete': 1 }, 38 | // these are always handy :) 39 | cleanPrototype = {}, 40 | toString = cleanPrototype.toString, 41 | undef, 42 | // local cache of resource definitions (lightweight promises) 43 | cache = {}, 44 | // local url cache 45 | urlCache = {}, 46 | // preload are files that must be loaded before any others 47 | preload = false, 48 | // net to catch anonymous define calls' arguments (non-IE browsers) 49 | argsNet, 50 | // RegExp's used later, pre-compiled here 51 | dontAddExtRx = /\?|\.js\b/, 52 | absUrlRx = /^\/|^[^:]+:\/\/|^[A-Za-z]:[\\/]/, 53 | findDotsRx = /(\.)(\.?)(?:$|\/([^\.\/]+.*)?)/g, 54 | removeCommentsRx = /\/\*[\s\S]*?\*\/|\/\/.*?[\n\r]/g, 55 | findRValueRequiresRx = /require\s*\(\s*(["'])(.*?[^\\])\1\s*\)|[^\\]?(["'])/g, 56 | splitCommaSepRx = /\s*,\s*/, 57 | cjsGetters, 58 | core; 59 | 60 | function noop () {} 61 | 62 | function isType (obj, type) { 63 | return toString.call(obj).indexOf('[object ' + type) == 0; 64 | } 65 | 66 | function normalizePkgDescriptor (descriptor, isPkg) { 67 | var main; 68 | 69 | descriptor.path = removeEndSlash(descriptor['path'] || descriptor['location'] || ''); 70 | if (isPkg) { 71 | main = descriptor['main'] || './main'; 72 | if (!isRelUrl(main)) main = './' + main; 73 | // trailing slashes trick reduceLeadingDots to see them as base ids 74 | descriptor.main = reduceLeadingDots(main, descriptor.name + '/'); 75 | } 76 | descriptor.config = descriptor['config']; 77 | 78 | return descriptor; 79 | } 80 | 81 | function isRelUrl (it) { 82 | return it.charAt(0) == '.'; 83 | } 84 | 85 | function isAbsUrl (it) { 86 | return absUrlRx.test(it); 87 | } 88 | 89 | function joinPath (path, file) { 90 | return removeEndSlash(path) + '/' + file; 91 | } 92 | 93 | function removeEndSlash (path) { 94 | return path && path.charAt(path.length - 1) == '/' ? path.substr(0, path.length - 1) : path; 95 | } 96 | 97 | function reduceLeadingDots (childId, baseId) { 98 | // this algorithm is similar to dojo's compactPath, which interprets 99 | // module ids of "." and ".." as meaning "grab the module whose name is 100 | // the same as my folder or parent folder". These special module ids 101 | // are not included in the AMD spec but seem to work in node.js, too. 102 | var removeLevels, normId, levels, isRelative, diff; 103 | 104 | removeLevels = 1; 105 | normId = childId; 106 | 107 | // remove leading dots and count levels 108 | if (isRelUrl(normId)) { 109 | isRelative = true; 110 | normId = normId.replace(findDotsRx, function (m, dot, doubleDot, remainder) { 111 | if (doubleDot) removeLevels++; 112 | return remainder || ''; 113 | }); 114 | } 115 | 116 | if (isRelative) { 117 | levels = baseId.split('/'); 118 | diff = levels.length - removeLevels; 119 | if (diff < 0) { 120 | // this is an attempt to navigate above parent module. 121 | // maybe dev wants a url or something. punt and return url; 122 | return childId; 123 | } 124 | levels.splice(diff, removeLevels); 125 | // normId || [] prevents concat from adding extra "/" when 126 | // normId is reduced to a blank string 127 | return levels.concat(normId || []).join('/'); 128 | } 129 | else { 130 | return normId; 131 | } 132 | } 133 | 134 | function pluginParts (id) { 135 | var delPos = id.indexOf('!'); 136 | return { 137 | resourceId: id.substr(delPos + 1), 138 | // resourceId can be zero length 139 | pluginId: delPos >= 0 && id.substr(0, delPos) 140 | }; 141 | } 142 | 143 | function Begetter () {} 144 | 145 | function beget (parent, mixin) { 146 | Begetter.prototype = parent || cleanPrototype; 147 | var child = new Begetter(); 148 | Begetter.prototype = cleanPrototype; 149 | for (var p in mixin) child[p] = mixin[p]; 150 | return child; 151 | } 152 | 153 | function Promise () { 154 | 155 | var self, thens, complete; 156 | 157 | self = this; 158 | thens = []; 159 | 160 | function then (resolved, rejected, progressed) { 161 | // capture calls to callbacks 162 | thens.push([resolved, rejected, progressed]); 163 | } 164 | 165 | function notify (which, arg) { 166 | // complete all callbacks 167 | var aThen, cb, i = 0; 168 | while ((aThen = thens[i++])) { 169 | cb = aThen[which]; 170 | if (cb) cb(arg); 171 | } 172 | } 173 | 174 | complete = function promiseComplete (success, arg) { 175 | // switch over to sync then() 176 | then = success ? 177 | function (resolved, rejected) { resolved && resolved(arg); } : 178 | function (resolved, rejected) { rejected && rejected(arg); }; 179 | // we no longer throw during multiple calls to resolve or reject 180 | // since we don't really provide useful information anyways. 181 | complete = noop; 182 | // complete all callbacks 183 | notify(success ? 0 : 1, arg); 184 | // no more notifications 185 | notify = noop; 186 | // release memory 187 | thens = undef; 188 | }; 189 | 190 | this.then = function (resolved, rejected, progressed) { 191 | then(resolved, rejected, progressed); 192 | return self; 193 | }; 194 | this.resolve = function (val) { 195 | self.resolved = val; 196 | complete(true, val); 197 | }; 198 | this.reject = function (ex) { 199 | self.rejected = ex; 200 | complete(false, ex); 201 | }; 202 | this.progress = function (msg) { 203 | notify(2, msg); 204 | } 205 | 206 | } 207 | 208 | function isPromise (o) { 209 | return o instanceof Promise || o instanceof CurlApi; 210 | } 211 | 212 | function when (promiseOrValue, callback, errback, progback) { 213 | // we can't just sniff for then(). if we do, resources that have a 214 | // then() method will make dependencies wait! 215 | if (isPromise(promiseOrValue)) { 216 | return promiseOrValue.then(callback, errback, progback); 217 | } 218 | else { 219 | return callback(promiseOrValue); 220 | } 221 | } 222 | 223 | /** 224 | * Returns a function that when executed, executes a lambda function, 225 | * but only executes it the number of times stated by howMany. 226 | * When done executing, it executes the completed function. Each callback 227 | * function receives the same parameters that are supplied to the 228 | * returned function each time it executes. In other words, they 229 | * are passed through. 230 | * @private 231 | * @param howMany {Number} must be greater than zero 232 | * @param lambda {Function} executed each time 233 | * @param completed {Function} only executes once when the counter 234 | * reaches zero 235 | * @returns {Function} 236 | */ 237 | function countdown (howMany, lambda, completed) { 238 | var result; 239 | return function () { 240 | if (--howMany >= 0 && lambda) result = lambda.apply(undef, arguments); 241 | // we want ==, not <=, since some callers expect call-once functionality 242 | if (howMany == 0 && completed) completed(result); 243 | return result; 244 | } 245 | } 246 | 247 | core = { 248 | 249 | /** 250 | * * reduceLeadingDots of id against parentId 251 | * - if there are too many dots (path goes beyond parent), it's a url 252 | * - return reduceLeadingDots of id against baseUrl + parentId; 253 | * * if id is a url (starts with dots or slash or protocol) 254 | * - pathInfo = { config: userCfg, url: url } 255 | * * if not a url, id-to-id transform here. 256 | * - main module expansion 257 | * - plugin prefix expansion 258 | * - coordinate main module expansion with plugin expansion 259 | * - main module expansion happens first 260 | * - future: other transforms? 261 | * @param id 262 | * @param parentId 263 | * @param cfg 264 | * @return {*} 265 | */ 266 | toAbsId: function (id, parentId, cfg) { 267 | var absId, pluginId, parts; 268 | 269 | absId = reduceLeadingDots(id, parentId); 270 | 271 | // if this is still a relative path, it must be a url 272 | // so just punt, otherwise... 273 | if (isRelUrl(absId)) return absId; 274 | 275 | // plugin id split 276 | parts = pluginParts(absId); 277 | pluginId = parts.pluginId; 278 | absId = pluginId || parts.resourceId; 279 | 280 | // main id expansion 281 | if (absId in cfg.pathMap) { 282 | absId = cfg.pathMap[absId].main || absId; 283 | } 284 | 285 | // plugin id expansion 286 | if (pluginId) { 287 | if (pluginId.indexOf('/') < 0 && !(pluginId in cfg.pathMap)) { 288 | absId = joinPath(cfg.pluginPath, pluginId); 289 | } 290 | absId = absId + '!' + parts.resourceId; 291 | } 292 | 293 | return absId; 294 | }, 295 | 296 | createContext: function (cfg, baseId, depNames, isPreload) { 297 | 298 | var def; 299 | 300 | def = new Promise(); 301 | def.id = baseId || ''; // '' == global 302 | def.isPreload = isPreload; 303 | def.depNames = depNames; 304 | def.config = cfg; 305 | 306 | // functions that dependencies will use: 307 | 308 | function toAbsId (childId, checkPlugins) { 309 | var absId, parts, plugin; 310 | 311 | absId = core.toAbsId(childId, def.id, cfg); 312 | if (!checkPlugins) return absId; 313 | 314 | parts = pluginParts(absId); 315 | if (!parts.pluginId) return absId; 316 | 317 | plugin = cache[parts.pluginId]; 318 | // check if plugin supports the normalize method 319 | if ('normalize' in plugin) { 320 | // note: dojo/has may return falsey values (0, actually) 321 | parts.resourceId = plugin['normalize'](parts.resourceId, toAbsId, def.config) || ''; 322 | } 323 | else { 324 | parts.resourceId = toAbsId(parts.resourceId); 325 | } 326 | return parts.pluginId + '!' + parts.resourceId; 327 | } 328 | 329 | function toUrl (n) { 330 | // the AMD spec states that we should not append an extension 331 | // in this function since it could already be appended. 332 | // we need to use toAbsId in case this is a module id. 333 | return core.resolvePathInfo(toAbsId(n, true), cfg).url; 334 | } 335 | 336 | function localRequire (ids, callback, errback) { 337 | var cb, rvid, childDef, earlyExport; 338 | 339 | // this is public, so send pure function 340 | // also fixes issue #41 341 | cb = callback && function () { callback.apply(undef, arguments[0]); }; 342 | 343 | // RValue require (CommonJS) 344 | if (isType(ids, 'String')) { 345 | if (cb) { 346 | throw new Error('require(id, callback) not allowed'); 347 | } 348 | // return resource 349 | rvid = toAbsId(ids, true); 350 | childDef = cache[rvid]; 351 | if (!(rvid in cache)) { 352 | // this should only happen when devs attempt their own 353 | // manual wrapping of cjs modules or get confused with 354 | // the callback syntax: 355 | throw new Error('Module not resolved: ' + rvid); 356 | } 357 | earlyExport = isPromise(childDef) && childDef.exports; 358 | return earlyExport || childDef; 359 | } 360 | else { 361 | when(core.getDeps(core.createContext(cfg, def.id, ids, isPreload)), cb, errback); 362 | } 363 | } 364 | 365 | def.require = localRequire; 366 | localRequire['toUrl'] = toUrl; 367 | def.toAbsId = toAbsId; 368 | 369 | return def; 370 | }, 371 | 372 | createResourceDef: function (cfg, id, isPreload) { 373 | var def, origResolve, execute; 374 | 375 | def = core.createContext(cfg, id, undef, isPreload); 376 | origResolve = def.resolve; 377 | 378 | // using countdown to only execute definition function once 379 | execute = countdown(1, function (deps) { 380 | def.deps = deps; 381 | try { 382 | return core.executeDefFunc(def); 383 | } 384 | catch (ex) { 385 | def.reject(ex); 386 | } 387 | }); 388 | 389 | // intercept resolve function to execute definition function 390 | // before resolving 391 | def.resolve = function resolve (deps) { 392 | when(isPreload || preload, function () { 393 | origResolve((cache[def.id] = urlCache[def.url] = execute(deps))); 394 | }); 395 | }; 396 | 397 | // track exports 398 | def.exportsReady = function executeFactory (deps) { 399 | when(isPreload || preload, function () { 400 | // only resolve early if we also use exports (to avoid 401 | // circular dependencies). def.exports will have already 402 | // been set by the getDeps loop before we get here. 403 | if (def.exports) { 404 | execute(deps); 405 | def.progress(msgFactoryExecuted); 406 | } 407 | }); 408 | }; 409 | 410 | return def; 411 | }, 412 | 413 | createPluginDef: function (cfg, id, resId, isPreload) { 414 | var def; 415 | 416 | // use resource id for local require and toAbsId 417 | def = core.createContext(cfg, resId, undef, isPreload); 418 | 419 | return def; 420 | }, 421 | 422 | getCjsRequire: function (def) { 423 | return def.require; 424 | }, 425 | 426 | getCjsExports: function (def) { 427 | return def.exports || (def.exports = {}); 428 | }, 429 | 430 | getCjsModule: function (def) { 431 | var module = def.module; 432 | if (!module) { 433 | module = def.module = { 434 | 'id': def.id, 435 | 'uri': core.getDefUrl(def), 436 | 'exports': core.getCjsExports(def), 437 | 'config': function () { return def.config; } 438 | }; 439 | module.exports = module['exports']; // oh closure compiler! 440 | } 441 | return module; 442 | }, 443 | 444 | getDefUrl: function (def) { 445 | // note: this is used by cjs module.uri 446 | return def.url || (def.url = core.checkToAddJsExt(def.require['toUrl'](def.id), def.config)); 447 | }, 448 | 449 | /** 450 | * Sets the curl() and define() APIs. 451 | * @param [cfg] {Object|Null} set of config params. If missing or null, 452 | * this function will set the default API! 453 | */ 454 | setApi: function (cfg) { 455 | /* 456 | scenarios: 457 | 1. global config sets apiName: "require" 458 | - first call to config sets api 459 | - second and later calls are ignored 460 | - prevCurl cannot exist 461 | 2. no global config, first call to config() sets api 462 | - first call to config has no api info 463 | - second call to config sets api 464 | - third and later calls must be ignored 465 | 3. global config that doesn't set api, first call does though 466 | - same as #2 467 | 4. api info is never set 468 | - how to know when to stop ignoring? 469 | 470 | objectives: 471 | 1. fail before mistakenly overwriting global[curlName] 472 | 2. allow rename/relocate of curl() and define() 473 | 3. restore curl() if we overwrote it 474 | */ 475 | 476 | var apiName, defName, apiObj, defObj, 477 | failMsg, okToOverwrite; 478 | 479 | apiName = curlName; 480 | defName = defineName; 481 | apiObj = defObj = global; 482 | failMsg = ' already exists'; 483 | 484 | // if we're not setting defaults 485 | if (cfg) { 486 | // is it ok to overwrite existing api functions? 487 | okToOverwrite = cfg['overwriteApi'] || cfg.overwriteApi; 488 | // allow dev to rename/relocate curl() to another object 489 | apiName = cfg['apiName'] || cfg.apiName || apiName; 490 | apiObj = cfg['apiContext'] || cfg.apiContext || apiObj; 491 | // define() too 492 | defName = cfg['defineName'] || cfg.defineName || defName; 493 | defObj = cfg['defineContext'] || cfg.defineContext || defObj; 494 | 495 | // curl() already existed, restore it if this is not a 496 | // setDefaults pass. dev must be a good citizen and set 497 | // apiName/apiContext (see below). 498 | if (prevCurl && isType(prevCurl, 'Function')) { 499 | // restore previous curl() 500 | global[curlName] = prevCurl; 501 | } 502 | prevCurl = null; // don't check ever again 503 | // ditto for define() 504 | if (prevDefine && isType(prevDefine, 'Function')) { 505 | // restore previous curl() 506 | global[defineName] = prevDefine; 507 | } 508 | prevDefine = null; // don't check ever again 509 | 510 | // check if we're mistakenly overwriting either api 511 | // if we're configuring, and there's a curl(), and it's not 512 | // ours -- and we're not explicitly overwriting -- throw! 513 | // Note: if we're setting defaults, we *must* overwrite curl 514 | // so that dev can configure it. This is no different than 515 | // noConflict()-type methods. 516 | if (!okToOverwrite) { 517 | if (apiObj[apiName] && apiObj[apiName] != _curl) { 518 | throw new Error(apiName + failMsg); 519 | } 520 | // check if we're overwriting amd api 521 | if (defObj[defName] && defObj[defName] != define) { 522 | throw new Error(defName + failMsg); 523 | } 524 | } 525 | 526 | } 527 | 528 | // set curl api 529 | apiObj[apiName] = _curl; 530 | 531 | // set AMD public api: define() 532 | defObj[defName] = define; 533 | 534 | }, 535 | 536 | config: function (cfg) { 537 | var prevCfg, newCfg, pluginCfgs, p; 538 | 539 | // convert from closure-safe names 540 | if ('baseUrl' in cfg) cfg.baseUrl = cfg['baseUrl']; 541 | if ('main' in cfg) cfg.main = cfg['main']; 542 | if ('preloads' in cfg) cfg.preloads = cfg['preloads']; 543 | if ('pluginPath' in cfg) cfg.pluginPath = cfg['pluginPath']; 544 | if ('dontAddFileExt' in cfg || cfg.dontAddFileExt) { 545 | cfg.dontAddFileExt = new RegExp(cfg['dontAddFileExt'] || cfg.dontAddFileExt); 546 | } 547 | 548 | prevCfg = userCfg; 549 | newCfg = beget(prevCfg, cfg); 550 | 551 | // create object to hold path map. 552 | // each plugin and package will have its own pathMap, too. 553 | newCfg.pathMap = beget(prevCfg.pathMap); 554 | pluginCfgs = cfg['plugins'] || {}; 555 | newCfg.plugins = beget(prevCfg.plugins); 556 | newCfg.paths = beget(prevCfg.paths, cfg.paths); 557 | newCfg.packages = beget(prevCfg.packages, cfg.packages); 558 | 559 | // temporary arrays of paths. this will be converted to 560 | // a regexp for fast path parsing. 561 | newCfg.pathList = []; 562 | 563 | // normalizes path/package info and places info on either 564 | // the global cfg.pathMap or on a plugin-specific altCfg.pathMap. 565 | // also populates a pathList on cfg or plugin configs. 566 | function fixAndPushPaths (coll, isPkg) { 567 | var id, pluginId, data, parts, currCfg, info; 568 | for (var name in coll) { 569 | data = coll[name]; 570 | if (isType(data, 'String')) data = { 571 | path: coll[name] 572 | }; 573 | // grab the package id, if specified. default to 574 | // property name, if missing. 575 | data.name = data.name || name; 576 | currCfg = newCfg; 577 | // check if this is a plugin-specific path 578 | parts = pluginParts(removeEndSlash(data.name)); 579 | id = parts.resourceId; 580 | pluginId = parts.pluginId; 581 | if (pluginId) { 582 | // plugin-specific path 583 | currCfg = pluginCfgs[pluginId]; 584 | if (!currCfg) { 585 | currCfg = pluginCfgs[pluginId] = beget(newCfg); 586 | currCfg.pathMap = beget(newCfg.pathMap); 587 | currCfg.pathList = []; 588 | } 589 | // remove plugin-specific path from coll 590 | delete coll[name]; 591 | } 592 | info = normalizePkgDescriptor(data, isPkg); 593 | if (info.config) info.config = beget(newCfg, info.config); 594 | info.specificity = id.split('/').length; 595 | if (id) { 596 | currCfg.pathMap[id] = info; 597 | currCfg.pathList.push(id); 598 | } 599 | else { 600 | // naked plugin name signifies baseUrl for plugin 601 | // resources. baseUrl could be relative to global 602 | // baseUrl. 603 | currCfg.baseUrl = core.resolveUrl(data.path, newCfg); 604 | } 605 | } 606 | } 607 | 608 | // adds the path matching regexp onto the cfg or plugin cfgs. 609 | function convertPathMatcher (cfg) { 610 | var pathMap = cfg.pathMap; 611 | cfg.pathRx = new RegExp('^(' + 612 | cfg.pathList.sort(function (a, b) { return pathMap[b].specificity - pathMap[a].specificity; } ) 613 | .join('|') 614 | .replace(/\/|\./g, '\\$&') + 615 | ')(?=\\/|$)' 616 | ); 617 | delete cfg.pathList; 618 | } 619 | 620 | // fix all new packages, then paths (in case there are 621 | // plugin-specific paths for a main module, such as wire!) 622 | fixAndPushPaths(cfg['packages'], true); 623 | fixAndPushPaths(cfg['paths'], false); 624 | 625 | // process plugins after packages in case we already perform an 626 | // id transform on a plugin (i.e. it's a package.main) 627 | for (p in pluginCfgs) { 628 | var absId = core.toAbsId(p + '!', '', newCfg); 629 | newCfg.plugins[absId.substr(0, absId.length - 1)] = pluginCfgs[p]; 630 | } 631 | pluginCfgs = newCfg.plugins; 632 | 633 | // create search regex for each path map 634 | for (p in pluginCfgs) { 635 | // inherit full config 636 | pluginCfgs[p] = beget(newCfg, pluginCfgs[p]); 637 | var pathList = pluginCfgs[p].pathList; 638 | if (pathList) { 639 | pluginCfgs[p].pathList = pathList.concat(newCfg.pathList); 640 | convertPathMatcher(pluginCfgs[p]); 641 | } 642 | } 643 | 644 | // ugh, this is ugly, but necessary until we refactor this function 645 | // copy previous pathMap items onto pathList 646 | for (p in prevCfg.pathMap) { 647 | if (!newCfg.pathMap.hasOwnProperty(p)) newCfg.pathList.push(p); 648 | } 649 | 650 | convertPathMatcher(newCfg); 651 | 652 | return newCfg; 653 | 654 | }, 655 | 656 | resolvePathInfo: function (absId, cfg) { 657 | // searches through the configured path mappings and packages 658 | var pathMap, pathInfo, path, pkgCfg; 659 | 660 | pathMap = cfg.pathMap; 661 | 662 | if (!isAbsUrl(absId)) { 663 | path = absId.replace(cfg.pathRx, function (match) { 664 | // TODO: remove fallbacks here since they should never need to happen 665 | pathInfo = pathMap[match] || {}; 666 | pkgCfg = pathInfo.config; 667 | return pathInfo.path || ''; 668 | }); 669 | } 670 | else { 671 | path = absId; 672 | } 673 | 674 | return { 675 | config: pkgCfg || userCfg, 676 | url: core.resolveUrl(path, cfg) 677 | }; 678 | }, 679 | 680 | resolveUrl: function (path, cfg) { 681 | var baseUrl = cfg.baseUrl; 682 | return baseUrl && !isAbsUrl(path) ? joinPath(baseUrl, path) : path; 683 | }, 684 | 685 | checkToAddJsExt: function (url, cfg) { 686 | // don't add extension if a ? is found in the url (query params) 687 | // i'd like to move this feature to a moduleLoader 688 | return url + ((cfg || userCfg).dontAddFileExt.test(url) ? '' : '.js'); 689 | }, 690 | 691 | loadScript: function (def, success, failure) { 692 | // script processing rules learned from RequireJS 693 | // TODO: pass a validate function into loadScript to check if a success really is a success 694 | 695 | // insert script 696 | var el = doc.createElement('script'); 697 | 698 | // initial script processing 699 | function process (ev) { 700 | ev = ev || global.event; 701 | // detect when it's done loading 702 | // ev.type == 'load' is for all browsers except IE6-9 703 | // IE6-9 need to use onreadystatechange and look for 704 | // el.readyState in {loaded, complete} (yes, we need both) 705 | if (ev.type == 'load' || readyStates[el.readyState]) { 706 | delete activeScripts[def.id]; 707 | // release event listeners 708 | el.onload = el.onreadystatechange = el.onerror = ''; // ie cries if we use undefined 709 | success(); 710 | } 711 | } 712 | 713 | function fail (e) { 714 | // some browsers send an event, others send a string, 715 | // but none of them send anything useful, so just say we failed: 716 | failure(new Error('Syntax or http error: ' + def.url)); 717 | } 718 | 719 | // set type first since setting other properties could 720 | // prevent us from setting this later 721 | // actually, we don't even need to set this at all 722 | //el.type = 'text/javascript'; 723 | // using dom0 event handlers instead of wordy w3c/ms 724 | el.onload = el.onreadystatechange = process; 725 | el.onerror = fail; 726 | // js! plugin uses alternate mimetypes 727 | el.type = def.mimetype || 'text/javascript'; 728 | // TODO: support other charsets? 729 | el.charset = 'utf-8'; 730 | el.async = !def.order; 731 | el.src = def.url; 732 | 733 | // loading will start when the script is inserted into the dom. 734 | // IE will load the script sync if it's in the cache, so 735 | // indicate the current resource definition if this happens. 736 | activeScripts[def.id] = el; 737 | 738 | head.insertBefore(el, insertBeforeEl); 739 | 740 | // the js! plugin uses this 741 | return el; 742 | }, 743 | 744 | extractCjsDeps: function (defFunc) { 745 | // Note: ignores require() inside strings and comments 746 | var source, ids = [], currQuote; 747 | // prefer toSource (FF) since it strips comments 748 | source = typeof defFunc == 'string' ? 749 | defFunc : 750 | defFunc.toSource ? defFunc.toSource() : defFunc.toString(); 751 | // remove comments, then look for require() or quotes 752 | source.replace(removeCommentsRx, '').replace(findRValueRequiresRx, function (m, rq, id, qq) { 753 | // if we encounter a string in the source, don't look for require() 754 | if (qq) { 755 | currQuote = currQuote == qq ? undef : currQuote; 756 | } 757 | // if we're not inside a quoted string 758 | else if (!currQuote) { 759 | ids.push(id); 760 | } 761 | return ''; // uses least RAM/CPU 762 | }); 763 | return ids; 764 | }, 765 | 766 | fixArgs: function (args) { 767 | // resolve args 768 | // valid combinations for define: 769 | // (string, array, object|function) sax|saf 770 | // (array, object|function) ax|af 771 | // (string, object|function) sx|sf 772 | // (object|function) x|f 773 | 774 | var id, deps, defFunc, defFuncArity, len, cjs; 775 | 776 | len = args.length; 777 | 778 | defFunc = args[len - 1]; 779 | defFuncArity = isType(defFunc, 'Function') ? defFunc.length : -1; 780 | 781 | if (len == 2) { 782 | if (isType(args[0], 'Array')) { 783 | deps = args[0]; 784 | } 785 | else { 786 | id = args[0]; 787 | } 788 | } 789 | else if (len == 3) { 790 | id = args[0]; 791 | deps = args[1]; 792 | } 793 | 794 | // Hybrid format: assume that a definition function with zero 795 | // dependencies and non-zero arity is a wrapped CommonJS module 796 | if (!deps && defFuncArity > 0) { 797 | cjs = true; 798 | deps = ['require', 'exports', 'module'].slice(0, defFuncArity).concat(core.extractCjsDeps(defFunc)); 799 | } 800 | 801 | return { 802 | id: id, 803 | deps: deps || [], 804 | res: defFuncArity >= 0 ? defFunc : function () { return defFunc; }, 805 | cjs: cjs 806 | }; 807 | }, 808 | 809 | executeDefFunc: function (def) { 810 | var resource, moduleThis; 811 | // the force of AMD is strong so anything returned 812 | // overrides exports. 813 | // node.js assumes `this` === `exports` so we do that 814 | // for all cjs-wrapped modules, just in case. 815 | // also, use module.exports if that was set 816 | // (node.js convention). 817 | // note: if .module exists, .exports exists. 818 | moduleThis = def.cjs ? def.exports : undef; 819 | resource = def.res.apply(moduleThis, def.deps); 820 | if (resource === undef && def.exports) { 821 | // note: exports will equal module.exports unless 822 | // module.exports was reassigned inside module. 823 | resource = def.module 824 | ? (def.exports = def.module['exports']) 825 | : def.exports; 826 | } 827 | return resource; 828 | }, 829 | 830 | defineResource: function (def, args) { 831 | 832 | def.res = args.res; 833 | def.cjs = args.cjs; 834 | def.depNames = args.deps; 835 | core.getDeps(def); 836 | 837 | }, 838 | 839 | getDeps: function (parentDef) { 840 | 841 | var i, names, deps, len, dep, completed, name, 842 | exportCollector, resolveCollector; 843 | 844 | deps = []; 845 | names = parentDef.depNames; 846 | len = names.length; 847 | 848 | if (names.length == 0) allResolved(); 849 | 850 | function collect (dep, index, alsoExport) { 851 | deps[index] = dep; 852 | if (alsoExport) exportCollector(dep, index); 853 | } 854 | 855 | // reducer-collectors 856 | exportCollector = countdown(len, collect, allExportsReady); 857 | resolveCollector = countdown(len, collect, allResolved); 858 | 859 | // initiate the resolution of all dependencies 860 | // Note: the correct handling of early exports relies on the 861 | // fact that the exports pseudo-dependency is always listed 862 | // before other module dependencies. 863 | for (i = 0; i < len; i++) { 864 | name = names[i]; 865 | // is this "require", "exports", or "module"? 866 | if (name in cjsGetters) { 867 | // a side-effect of cjsGetters is that the cjs 868 | // property is also set on the def. 869 | resolveCollector(cjsGetters[name](parentDef), i, true); 870 | // if we are using the `module` or `exports` cjs variables, 871 | // signal any waiters/parents that we can export 872 | // early (see progress callback in getDep below). 873 | // note: this may fire for `require` as well, if it 874 | // is listed after `module` or `exports` in the deps list, 875 | // but that is okay since all waiters will only record 876 | // it once. 877 | if (parentDef.exports) { 878 | parentDef.progress(msgUsingExports); 879 | } 880 | } 881 | // check for blanks. fixes #32. 882 | // this helps support yepnope.js, has.js, and the has! plugin 883 | else if (!name) { 884 | resolveCollector(undef, i, true); 885 | } 886 | // normal module or plugin resource 887 | else { 888 | getDep(name, i); 889 | } 890 | } 891 | 892 | return parentDef; 893 | 894 | function getDep (name, index) { 895 | var resolveOnce, exportOnce, childDef, earlyExport; 896 | 897 | resolveOnce = countdown(1, function (dep) { 898 | exportOnce(dep); 899 | resolveCollector(dep, index); 900 | }); 901 | exportOnce = countdown(1, function (dep) { 902 | exportCollector(dep, index); 903 | }); 904 | 905 | // get child def / dep 906 | childDef = core.fetchDep(name, parentDef); 907 | 908 | // check if childDef can export. if it can, then 909 | // we missed the notification and it will never fire in the 910 | // when() below. 911 | earlyExport = isPromise(childDef) && childDef.exports; 912 | if (earlyExport) { 913 | exportOnce(earlyExport); 914 | } 915 | 916 | when(childDef, 917 | resolveOnce, 918 | parentDef.reject, 919 | parentDef.exports && function (msg) { 920 | // messages are only sent from childDefs that support 921 | // exports, and we only notify parents that understand 922 | // exports too. 923 | if (childDef.exports) { 924 | if (msg == msgUsingExports) { 925 | // if we're using exports cjs variable on both sides 926 | exportOnce(childDef.exports); 927 | } 928 | else if (msg == msgFactoryExecuted) { 929 | resolveOnce(childDef.exports); 930 | } 931 | } 932 | } 933 | ); 934 | } 935 | 936 | function allResolved () { 937 | parentDef.resolve(deps); 938 | } 939 | 940 | function allExportsReady () { 941 | parentDef.exportsReady && parentDef.exportsReady(deps); 942 | } 943 | 944 | }, 945 | 946 | fetchResDef: function (def) { 947 | 948 | // ensure url is computed 949 | core.getDefUrl(def); 950 | 951 | core.loadScript(def, 952 | 953 | function () { 954 | var args = argsNet; 955 | argsNet = undef; // reset it before we get deps 956 | 957 | // if our resource was not explicitly defined with an id (anonymous) 958 | // Note: if it did have an id, it will be resolved in the define() 959 | if (def.useNet !== false) { 960 | 961 | // if !args, nothing was added to the argsNet 962 | if (!args || args.ex) { 963 | def.reject(new Error(((args && args.ex) || 'define() missing or duplicated: ' + def.url))); 964 | } 965 | else { 966 | core.defineResource(def, args); 967 | } 968 | } 969 | 970 | }, 971 | 972 | def.reject 973 | 974 | ); 975 | 976 | return def; 977 | 978 | }, 979 | 980 | fetchDep: function (depName, parentDef) { 981 | var toAbsId, isPreload, parentCfg, parts, absId, mainId, loaderId, pluginId, 982 | resId, pathInfo, def, tempDef, resCfg; 983 | 984 | toAbsId = parentDef.toAbsId; 985 | isPreload = parentDef.isPreload; 986 | parentCfg = parentDef.config || userCfg; // is this fallback necessary? 987 | 988 | absId = toAbsId(depName); 989 | 990 | if (absId in cache) { 991 | // module already exists in cache 992 | mainId = absId; 993 | } 994 | else { 995 | // check for plugin loaderId 996 | parts = pluginParts(absId); 997 | resId = parts.resourceId; 998 | // get id of first resource to load (which could be a plugin) 999 | mainId = parts.pluginId || resId; 1000 | pathInfo = core.resolvePathInfo(mainId, parentCfg); 1001 | } 1002 | 1003 | if (!(absId in cache)) { 1004 | resCfg = core.resolvePathInfo(resId, parentCfg).config; 1005 | if (parts.pluginId) { 1006 | loaderId = mainId; 1007 | } 1008 | else { 1009 | // get custom module loader from package config if not a plugin 1010 | // TODO: move config.moduleLoader to config.loader 1011 | loaderId = resCfg['moduleLoader'] || resCfg.moduleLoader 1012 | || resCfg['loader'] || resCfg.loader; 1013 | if (loaderId) { 1014 | // TODO: allow transforms to have relative module ids? 1015 | // (we could do this by returning package location from 1016 | // resolvePathInfo. why not return all package info?) 1017 | resId = mainId; 1018 | mainId = loaderId; 1019 | pathInfo = core.resolvePathInfo(loaderId, parentCfg); 1020 | } 1021 | } 1022 | } 1023 | 1024 | if (mainId in cache) { 1025 | def = cache[mainId]; 1026 | } 1027 | else if (pathInfo.url in urlCache) { 1028 | def = cache[mainId] = urlCache[pathInfo.url]; 1029 | } 1030 | else { 1031 | def = core.createResourceDef(resCfg, mainId, isPreload); 1032 | // TODO: can this go inside createResourceDef? 1033 | // TODO: can we pass pathInfo.url to createResourceDef instead? 1034 | def.url = core.checkToAddJsExt(pathInfo.url, pathInfo.config); 1035 | cache[mainId] = urlCache[pathInfo.url] = def; 1036 | core.fetchResDef(def); 1037 | } 1038 | 1039 | // plugin or transformer 1040 | if (mainId == loaderId) { 1041 | 1042 | // use plugin's config if specified 1043 | if (parts.pluginId && parentCfg.plugins[parts.pluginId]) { 1044 | resCfg = parentCfg.plugins[parts.pluginId]; 1045 | } 1046 | // we need to use an anonymous promise until plugin tells 1047 | // us normalized id. then, we need to consolidate the promises 1048 | // below. Note: exports objects will be different between 1049 | // pre-normalized and post-normalized defs! does this matter? 1050 | // don't put this resource def in the cache because if the 1051 | // resId doesn't change, the check if this is a new 1052 | // normalizedDef (below) will think it's already being loaded. 1053 | tempDef = new Promise(); 1054 | 1055 | // wait for plugin resource def 1056 | when(def, function(plugin) { 1057 | var normalizedDef, fullId, dynamic; 1058 | 1059 | dynamic = plugin['dynamic']; 1060 | // check if plugin supports the normalize method 1061 | if ('normalize' in plugin) { 1062 | // note: dojo/has may return falsey values (0, actually) 1063 | resId = plugin['normalize'](resId, toAbsId, def.config) || ''; 1064 | } 1065 | else { 1066 | resId = toAbsId(resId); 1067 | } 1068 | 1069 | // use the full id (loaderId + id) to id plugin resources 1070 | // so multiple plugins may each process the same resource 1071 | // resId could be blank if the plugin doesn't require any (e.g. "domReady!") 1072 | fullId = loaderId + '!' + resId; 1073 | normalizedDef = cache[fullId]; 1074 | 1075 | // if this is our first time fetching this (normalized) def 1076 | if (!(fullId in cache)) { 1077 | 1078 | // because we're using resId, plugins, such as wire!, 1079 | // can use paths relative to the resource 1080 | normalizedDef = core.createPluginDef(resCfg, fullId, resId, isPreload); 1081 | 1082 | // don't cache non-determinate "dynamic" resources 1083 | if (!dynamic) { 1084 | cache[fullId] = normalizedDef; 1085 | } 1086 | 1087 | // curl's plugins prefer to receive a deferred, 1088 | // but to be compatible with AMD spec, we have to 1089 | // piggy-back on the callback function parameter: 1090 | var loaded = function (res) { 1091 | if (!dynamic) cache[fullId] = res; 1092 | normalizedDef.resolve(res); 1093 | }; 1094 | loaded['resolve'] = loaded; 1095 | loaded['reject'] = loaded['error'] = normalizedDef.reject; 1096 | 1097 | // load the resource! 1098 | plugin.load(resId, normalizedDef.require, loaded, resCfg); 1099 | 1100 | } 1101 | 1102 | // chain defs (resolve when plugin.load executes) 1103 | if (tempDef != normalizedDef) { 1104 | when(normalizedDef, tempDef.resolve, tempDef.reject, tempDef.progress); 1105 | } 1106 | 1107 | }, tempDef.reject); 1108 | 1109 | } 1110 | 1111 | // return tempDef if this is a plugin-based resource 1112 | return tempDef || def; 1113 | }, 1114 | 1115 | getCurrentDefName: function () { 1116 | // IE6-9 mark the currently executing thread as "interactive" 1117 | // Note: Opera lies about which scripts are "interactive", so we 1118 | // just have to test for it. Opera provides a true browser test, not 1119 | // a UA sniff, thankfully. 1120 | // learned this trick from James Burke's RequireJS 1121 | var def; 1122 | if (!isType(global.opera, 'Opera')) { 1123 | for (var d in activeScripts) { 1124 | if (activeScripts[d].readyState == 'interactive') { 1125 | def = d; 1126 | break; 1127 | } 1128 | } 1129 | } 1130 | return def; 1131 | }, 1132 | 1133 | findScript: function (predicate) { 1134 | var i = 0, scripts, script; 1135 | scripts = doc && (doc.scripts || doc.getElementsByTagName('script')); 1136 | while (scripts && (script = scripts[i++])) { 1137 | if (predicate(script)) return script; 1138 | } 1139 | }, 1140 | 1141 | extractDataAttrConfig: function () { 1142 | var script, attr = ''; 1143 | script = core.findScript(function (script) { 1144 | var run; 1145 | // find data-curl-run attr on script element 1146 | run = script.getAttribute(bootScriptAttr); 1147 | if (run) attr = run; 1148 | return run; 1149 | }); 1150 | // removeAttribute is wonky (in IE6?) but this works 1151 | if (script) { 1152 | script.setAttribute(bootScriptAttr, ''); 1153 | } 1154 | return attr; 1155 | }, 1156 | 1157 | bootScript: function () { 1158 | var urls = bootScript.split(splitCommaSepRx); 1159 | if (urls.length) { 1160 | load(); 1161 | } 1162 | function load () { 1163 | // Note: IE calls success handler if it gets a 400+. 1164 | core.loadScript({ url: urls.shift() }, check, check); 1165 | } 1166 | function check () { 1167 | // check if run.js called curl() or curl.config() 1168 | if (bootScript) { 1169 | if (urls.length) { 1170 | // show an error message 1171 | core.nextTurn(fail); 1172 | // try next 1173 | load(); 1174 | } 1175 | else fail('run.js script did not run.'); 1176 | } 1177 | } 1178 | function fail (msg) { 1179 | throw new Error(msg || 'Primary run.js failed. Trying fallback.'); 1180 | } 1181 | }, 1182 | 1183 | nextTurn: function (task) { 1184 | setTimeout(task, 0); 1185 | } 1186 | 1187 | }; 1188 | 1189 | // hook-up cjs free variable getters 1190 | cjsGetters = {'require': core.getCjsRequire, 'exports': core.getCjsExports, 'module': core.getCjsModule}; 1191 | 1192 | function _curl (/* various */) { 1193 | var args, promise, cfg; 1194 | 1195 | // indicate we're no longer waiting for a boot script 1196 | bootScript = ''; 1197 | 1198 | args = [].slice.call(arguments); 1199 | 1200 | // extract config, if it's specified 1201 | if (isType(args[0], 'Object')) { 1202 | cfg = args.shift(); 1203 | promise = _config(cfg); 1204 | } 1205 | 1206 | return new CurlApi(args[0], args[1], args[2], promise); 1207 | } 1208 | 1209 | function _config (cfg, callback, errback) { 1210 | var pPromise, main, fallback; 1211 | 1212 | // indicate we're no longer waiting for a boot script 1213 | bootScript = ''; 1214 | 1215 | if (cfg) { 1216 | core.setApi(cfg); 1217 | userCfg = core.config(cfg); 1218 | // check for preloads 1219 | if ('preloads' in cfg) { 1220 | pPromise = new CurlApi(cfg['preloads'], undef, errback, preload, true); 1221 | // yes, this is hacky and embarrassing. now that we've got that 1222 | // settled... until curl has deferred factory execution, this 1223 | // is the only way to stop preloads from dead-locking when 1224 | // they have dependencies inside a bundle. 1225 | core.nextTurn(function () { preload = pPromise; }); 1226 | } 1227 | // check for main module(s). all modules wait for preloads implicitly. 1228 | main = cfg['main']; 1229 | if (main) { 1230 | return new CurlApi(main, callback, errback); 1231 | } 1232 | } 1233 | } 1234 | 1235 | // thanks to Joop Ringelberg for helping troubleshoot the API 1236 | function CurlApi (ids, callback, errback, waitFor, isPreload) { 1237 | var then, ctx; 1238 | 1239 | ctx = core.createContext(userCfg, undef, [].concat(ids), isPreload); 1240 | 1241 | this['then'] = this.then = then = function (resolved, rejected) { 1242 | when(ctx, 1243 | // return the dependencies as arguments, not an array 1244 | function (deps) { 1245 | if (resolved) resolved.apply(undef, deps); 1246 | }, 1247 | // just throw if the dev didn't specify an error handler 1248 | function (ex) { 1249 | if (rejected) rejected(ex); else throw ex; 1250 | } 1251 | ); 1252 | return this; 1253 | }; 1254 | 1255 | this['next'] = function (ids, cb, eb) { 1256 | // chain api 1257 | return new CurlApi(ids, cb, eb, ctx); 1258 | }; 1259 | 1260 | this['config'] = _config; 1261 | 1262 | if (callback || errback) then(callback, errback); 1263 | 1264 | // ensure next-turn so inline code can execute first 1265 | core.nextTurn(function () { 1266 | when(isPreload || preload, function () { 1267 | when(waitFor, function () { core.getDeps(ctx); }, errback); 1268 | }); 1269 | }); 1270 | } 1271 | 1272 | _curl['version'] = version; 1273 | _curl['config'] = _config; 1274 | 1275 | function _define (args) { 1276 | 1277 | var id, def, pathInfo; 1278 | 1279 | id = args.id; 1280 | 1281 | if (id == undef) { 1282 | if (argsNet !== undef) { 1283 | argsNet = { ex: 'Multiple anonymous defines encountered' }; 1284 | } 1285 | else if (!(id = core.getCurrentDefName())/* intentional assignment */) { 1286 | // anonymous define(), defer processing until after script loads 1287 | argsNet = args; 1288 | } 1289 | } 1290 | if (id != undef) { 1291 | // named define(), it is in the cache if we are loading a dependency 1292 | // (could also be a secondary define() appearing in a built file, etc.) 1293 | def = cache[id]; 1294 | if (!(id in cache)) { 1295 | // id is an absolute id in this case, so we can get the config. 1296 | pathInfo = core.resolvePathInfo(id, userCfg); 1297 | def = core.createResourceDef(pathInfo.config, id); 1298 | cache[id] = def; 1299 | } 1300 | if (!isPromise(def)) throw new Error('duplicate define: ' + id); 1301 | // check if this resource has already been resolved 1302 | def.useNet = false; 1303 | core.defineResource(def, args); 1304 | } 1305 | 1306 | } 1307 | 1308 | function define () { 1309 | // wrap inner _define so it can be replaced without losing define.amd 1310 | var args = core.fixArgs(arguments); 1311 | _define(args); 1312 | } 1313 | 1314 | // indicate our capabilities: 1315 | define['amd'] = { 'plugins': true, 'jQuery': true, 'curl': version }; 1316 | 1317 | // default configs 1318 | userCfg = { 1319 | baseUrl: '', 1320 | pluginPath: 'curl/plugin', 1321 | dontAddFileExt: dontAddExtRx, 1322 | paths: {}, 1323 | packages: {}, 1324 | plugins: {}, 1325 | pathMap: {}, 1326 | pathRx: /$^/ 1327 | }; 1328 | 1329 | // handle pre-existing global 1330 | prevCurl = global[curlName]; 1331 | prevDefine = global[defineName]; 1332 | 1333 | // only run config if there is something to config (perf saver?) 1334 | if (prevCurl && isType(prevCurl, 'Object')) { 1335 | // remove global curl object 1336 | global[curlName] = undef; // can't use delete in IE 6-8 1337 | // configure curl 1338 | _config(prevCurl); 1339 | } 1340 | else { 1341 | // set default api 1342 | core.setApi(); 1343 | } 1344 | 1345 | // look for "data-curl-run" directive 1346 | bootScript = core.extractDataAttrConfig(); 1347 | // wait a bit in case curl.js is bundled into the boot script 1348 | if (bootScript) core.nextTurn(core.bootScript); 1349 | 1350 | // allow curl to be a dependency 1351 | cache[curlName] = _curl; 1352 | 1353 | // expose curl core for special plugins and modules 1354 | // Note: core overrides will only work in either of two scenarios: 1355 | // 1. the files are running un-compressed (Google Closure or Uglify) 1356 | // 2. the overriding module was compressed into the same file as curl.js 1357 | // Compiling curl and the overriding module separately won't work. 1358 | cache['curl/_privileged'] = { 1359 | 'core': core, 1360 | 'cache': cache, 1361 | 'config': function () { return userCfg; }, 1362 | '_define': _define, 1363 | '_curl': _curl, 1364 | 'Promise': Promise 1365 | }; 1366 | 1367 | }(this.window || (typeof global != 'undefined' && global) || this)); 1368 | -------------------------------------------------------------------------------- /WebContent/plugins/require.js: -------------------------------------------------------------------------------- 1 | /* 2 | RequireJS 2.1.19 Copyright (c) 2010-2015, The Dojo Foundation All Rights Reserved. 3 | Available via the MIT or new BSD license. 4 | see: http://github.com/jrburke/requirejs for details 5 | */ 6 | var requirejs,require,define; 7 | (function(ba){function G(b){return"[object Function]"===K.call(b)}function H(b){return"[object Array]"===K.call(b)}function v(b,c){if(b){var d;for(d=0;dthis.depCount&&!this.defined){if(G(l)){if(this.events.error&&this.map.isDefine||e.onError!==ca)try{f=h.execCb(c,l,b,f)}catch(d){a=d}else f=h.execCb(c,l,b,f);this.map.isDefine&&void 0===f&&((b=this.module)?f=b.exports:this.usingExports&& 19 | (f=this.exports));if(a)return a.requireMap=this.map,a.requireModules=this.map.isDefine?[this.map.id]:null,a.requireType=this.map.isDefine?"define":"require",w(this.error=a)}else f=l;this.exports=f;if(this.map.isDefine&&!this.ignore&&(q[c]=f,e.onResourceLoad))e.onResourceLoad(h,this.map,this.depMaps);y(c);this.defined=!0}this.defining=!1;this.defined&&!this.defineEmitted&&(this.defineEmitted=!0,this.emit("defined",this.exports),this.defineEmitComplete=!0)}}else this.fetch()}},callPlugin:function(){var a= 20 | this.map,b=a.id,d=i(a.prefix);this.depMaps.push(d);s(d,"defined",u(this,function(f){var l,d;d=n(aa,this.map.id);var g=this.map.name,P=this.map.parentMap?this.map.parentMap.name:null,p=h.makeRequire(a.parentMap,{enableBuildCallback:!0});if(this.map.unnormalized){if(f.normalize&&(g=f.normalize(g,function(a){return c(a,P,!0)})||""),f=i(a.prefix+"!"+g,this.map.parentMap),s(f,"defined",u(this,function(a){this.init([],function(){return a},null,{enabled:!0,ignore:!0})})),d=n(m,f.id)){this.depMaps.push(f); 21 | if(this.events.error)d.on("error",u(this,function(a){this.emit("error",a)}));d.enable()}}else d?(this.map.url=h.nameToUrl(d),this.load()):(l=u(this,function(a){this.init([],function(){return a},null,{enabled:!0})}),l.error=u(this,function(a){this.inited=!0;this.error=a;a.requireModules=[b];B(m,function(a){0===a.map.id.indexOf(b+"_unnormalized")&&y(a.map.id)});w(a)}),l.fromText=u(this,function(f,c){var d=a.name,g=i(d),P=M;c&&(f=c);P&&(M=!1);r(g);t(k.config,b)&&(k.config[d]=k.config[b]);try{e.exec(f)}catch(m){return w(C("fromtexteval", 22 | "fromText eval for "+b+" failed: "+m,m,[b]))}P&&(M=!0);this.depMaps.push(g);h.completeLoad(d);p([d],l)}),f.load(a.name,p,l,k))}));h.enable(d,this);this.pluginMaps[d.id]=d},enable:function(){V[this.map.id]=this;this.enabling=this.enabled=!0;v(this.depMaps,u(this,function(a,b){var c,f;if("string"===typeof a){a=i(a,this.map.isDefine?this.map:this.map.parentMap,!1,!this.skipMap);this.depMaps[b]=a;if(c=n(L,a.id)){this.depExports[b]=c(this);return}this.depCount+=1;s(a,"defined",u(this,function(a){this.undefed|| 23 | (this.defineDep(b,a),this.check())}));this.errback?s(a,"error",u(this,this.errback)):this.events.error&&s(a,"error",u(this,function(a){this.emit("error",a)}))}c=a.id;f=m[c];!t(L,c)&&(f&&!f.enabled)&&h.enable(a,this)}));B(this.pluginMaps,u(this,function(a){var b=n(m,a.id);b&&!b.enabled&&h.enable(a,this)}));this.enabling=!1;this.check()},on:function(a,b){var c=this.events[a];c||(c=this.events[a]=[]);c.push(b)},emit:function(a,b){v(this.events[a],function(a){a(b)});"error"===a&&delete this.events[a]}}; 24 | h={config:k,contextName:b,registry:m,defined:q,urlFetched:S,defQueue:A,Module:Z,makeModuleMap:i,nextTick:e.nextTick,onError:w,configure:function(a){a.baseUrl&&"/"!==a.baseUrl.charAt(a.baseUrl.length-1)&&(a.baseUrl+="/");var b=k.shim,c={paths:!0,bundles:!0,config:!0,map:!0};B(a,function(a,b){c[b]?(k[b]||(k[b]={}),U(k[b],a,!0,!0)):k[b]=a});a.bundles&&B(a.bundles,function(a,b){v(a,function(a){a!==b&&(aa[a]=b)})});a.shim&&(B(a.shim,function(a,c){H(a)&&(a={deps:a});if((a.exports||a.init)&&!a.exportsFn)a.exportsFn= 25 | h.makeShimExports(a);b[c]=a}),k.shim=b);a.packages&&v(a.packages,function(a){var b,a="string"===typeof a?{name:a}:a;b=a.name;a.location&&(k.paths[b]=a.location);k.pkgs[b]=a.name+"/"+(a.main||"main").replace(ia,"").replace(Q,"")});B(m,function(a,b){!a.inited&&!a.map.unnormalized&&(a.map=i(b,null,!0))});if(a.deps||a.callback)h.require(a.deps||[],a.callback)},makeShimExports:function(a){return function(){var b;a.init&&(b=a.init.apply(ba,arguments));return b||a.exports&&da(a.exports)}},makeRequire:function(a, 26 | j){function g(c,d,p){var k,n;j.enableBuildCallback&&(d&&G(d))&&(d.__requireJsBuild=!0);if("string"===typeof c){if(G(d))return w(C("requireargs","Invalid require call"),p);if(a&&t(L,c))return L[c](m[a.id]);if(e.get)return e.get(h,c,a,g);k=i(c,a,!1,!0);k=k.id;return!t(q,k)?w(C("notloaded",'Module name "'+k+'" has not been loaded yet for context: '+b+(a?"":". Use require([])"))):q[k]}J();h.nextTick(function(){J();n=r(i(null,a));n.skipMap=j.skipMap;n.init(c,d,p,{enabled:!0});D()});return g}j=j||{};U(g, 27 | {isBrowser:z,toUrl:function(b){var d,e=b.lastIndexOf("."),j=b.split("/")[0];if(-1!==e&&(!("."===j||".."===j)||1g.attachEvent.toString().indexOf("[native code"))&&!Y?(M=!0,g.attachEvent("onreadystatechange",b.onScriptLoad)):(g.addEventListener("load",b.onScriptLoad,!1),g.addEventListener("error",b.onScriptError,!1));g.src=d;J=g;D?y.insertBefore(g,D):y.appendChild(g);J=null;return g}if(ea)try{importScripts(d),b.completeLoad(c)}catch(i){b.onError(C("importscripts","importScripts failed for "+c+" at "+d,i,[c]))}};z&&!s.skipDataMain&&T(document.getElementsByTagName("script"), 35 | function(b){y||(y=b.parentNode);if(I=b.getAttribute("data-main"))return r=I,s.baseUrl||(E=r.split("/"),r=E.pop(),O=E.length?E.join("/")+"/":"./",s.baseUrl=O),r=r.replace(Q,""),e.jsExtRegExp.test(r)&&(r=I),s.deps=s.deps?s.deps.concat(r):[r],!0});define=function(b,c,d){var e,g;"string"!==typeof b&&(d=c,c=b,b=null);H(c)||(d=c,c=null);!c&&G(d)&&(c=[],d.length&&(d.toString().replace(ka,"").replace(la,function(b,d){c.push(d)}),c=(1===d.length?["require"]:["require","exports","module"]).concat(c)));if(M){if(!(e= 36 | J))N&&"interactive"===N.readyState||T(document.getElementsByTagName("script"),function(b){if("interactive"===b.readyState)return N=b}),e=N;e&&(b||(b=e.getAttribute("data-requiremodule")),g=F[e.getAttribute("data-requirecontext")])}(g?g.defQueue:R).push([b,c,d])};define.amd={jQuery:!0};e.exec=function(b){return eval(b)};e(s)}})(this); 37 | -------------------------------------------------------------------------------- /WebContent/plugins/typescript/typings/jquery.d.ts: -------------------------------------------------------------------------------- 1 | /* ***************************************************************************** 2 | Copyright (c) Microsoft Corporation. All rights reserved. 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | this file except in compliance with the License. You may obtain a copy of the 5 | License at http://www.apache.org/licenses/LICENSE-2.0 6 | 7 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 8 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 9 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 10 | MERCHANTABLITY OR NON-INFRINGEMENT. 11 | 12 | See the Apache Version 2.0 License for specific language governing permissions 13 | and limitations under the License. 14 | ***************************************************************************** */ 15 | 16 | // Typing for the jQuery library, version 1.10 17 | 18 | /* 19 | Interface for the AJAX setting that will configure the AJAX request 20 | */ 21 | interface JQueryAjaxSettings { 22 | accepts?: any; 23 | async?: boolean; 24 | beforeSend? (jqXHR: JQueryXHR, settings: JQueryAjaxSettings): any; 25 | cache?: boolean; 26 | complete? (jqXHR: JQueryXHR, textStatus: string): any; 27 | contents?: { [key: string]: any; }; 28 | contentType?: any; 29 | context?: any; 30 | converters?: { [key: string]: any; }; 31 | crossDomain?: boolean; 32 | data?: any; 33 | dataFilter? (data: any, ty: any): any; 34 | dataType?: string; 35 | error? (jqXHR: JQueryXHR, textStatus: string, errorThrow: string): any; 36 | global?: boolean; 37 | headers?: { [key: string]: any; }; 38 | ifModified?: boolean; 39 | isLocal?: boolean; 40 | jsonp?: string; 41 | jsonpCallback?: any; 42 | mimeType?: string; 43 | password?: string; 44 | processData?: boolean; 45 | scriptCharset?: string; 46 | statusCode?: { [key: string]: any; }; 47 | success? (data: any, textStatus: string, jqXHR: JQueryXHR): any; 48 | timeout?: number; 49 | traditional?: boolean; 50 | type?: string; 51 | url?: string; 52 | username?: string; 53 | xhr?: any; 54 | xhrFields?: { [key: string]: any; }; 55 | } 56 | 57 | /* 58 | Interface for the jqXHR object 59 | */ 60 | interface JQueryXHR extends XMLHttpRequest { 61 | overrideMimeType(): any; 62 | } 63 | 64 | /* 65 | Interface for the JQuery callback 66 | */ 67 | interface JQueryCallback { 68 | add(...callbacks: any[]): any; 69 | disable(): any; 70 | empty(): any; 71 | fire(...arguments: any[]): any; 72 | fired(): boolean; 73 | fireWith(context: any, ...args: any[]): any; 74 | has(callback: any): boolean; 75 | lock(): any; 76 | locked(): boolean; 77 | removed(...callbacks: any[]): any; 78 | } 79 | 80 | /* 81 | Interface for the JQuery promise, part of callbacks 82 | */ 83 | interface JQueryPromise { 84 | always(...alwaysCallbacks: any[]): JQueryDeferred; 85 | done(...doneCallbacks: any[]): JQueryDeferred; 86 | fail(...failCallbacks: any[]): JQueryDeferred; 87 | pipe(doneFilter?: (x: any) => any, failFilter?: (x: any) => any, progressFilter?: (x: any) => any): JQueryPromise; 88 | then(doneCallbacks: any, failCallbacks: any, progressCallbacks?: any): JQueryDeferred; 89 | } 90 | 91 | /* 92 | Interface for the JQuery deferred, part of callbacks 93 | */ 94 | interface JQueryDeferred extends JQueryPromise { 95 | notify(...args: any[]): JQueryDeferred; 96 | notifyWith(context: any, ...args: any[]): JQueryDeferred; 97 | 98 | progress(...progressCallbacks: any[]): JQueryDeferred; 99 | reject(...args: any[]): JQueryDeferred; 100 | rejectWith(context: any, ...args: any[]): JQueryDeferred; 101 | resolve(...args: any[]): JQueryDeferred; 102 | resolveWith(context: any, ...args: any[]): JQueryDeferred; 103 | state(): string; 104 | then(doneCallbacks: any, failCallbacks?: any, progressCallbacks?: any): JQueryDeferred; 105 | } 106 | 107 | /* 108 | Interface of the JQuery extension of the W3C event object 109 | */ 110 | interface JQueryEventObject extends Event { 111 | data: any; 112 | delegateTarget: Element; 113 | isDefaultPrevented(): boolean; 114 | isImmediatePropogationStopped(): boolean; 115 | isPropogationStopped(): boolean; 116 | namespace: string; 117 | preventDefault(): any; 118 | relatedTarget: Element; 119 | result: any; 120 | stopImmediatePropagation(): void; 121 | stopPropagation(): void; 122 | pageX: number; 123 | pageY: number; 124 | which: number; 125 | metaKey: any; 126 | } 127 | 128 | /* 129 | Collection of properties of the current browser 130 | */ 131 | interface JQueryBrowserInfo { 132 | safari: boolean; 133 | opera: boolean; 134 | msie: boolean; 135 | mozilla: boolean; 136 | version: string; 137 | } 138 | 139 | interface JQuerySupport { 140 | ajax?: boolean; 141 | boxModel?: boolean; 142 | changeBubbles?: boolean; 143 | checkClone?: boolean; 144 | checkOn?: boolean; 145 | cors?: boolean; 146 | cssFloat?: boolean; 147 | hrefNormalized?: boolean; 148 | htmlSerialize?: boolean; 149 | leadingWhitespace?: boolean; 150 | noCloneChecked?: boolean; 151 | noCloneEvent?: boolean; 152 | opacity?: boolean; 153 | optDisabled?: boolean; 154 | optSelected?: boolean; 155 | scriptEval? (): boolean; 156 | style?: boolean; 157 | submitBubbles?: boolean; 158 | tbody?: boolean; 159 | } 160 | 161 | interface JQueryTransport { 162 | send(headers: { [index: string]: string; }, completeCallback: (status: number, statusText: string, responses: { [dataType: string]: any; }, headers: string) => void): void; 163 | abort(): void; 164 | } 165 | 166 | /* 167 | Static members of jQuery (those on $ and jQuery themselves) 168 | */ 169 | interface JQueryStatic { 170 | 171 | // AJAX 172 | ajax(settings: JQueryAjaxSettings): JQueryXHR; 173 | ajax(url: string, settings: JQueryAjaxSettings): JQueryXHR; 174 | 175 | ajaxPrefilter(handler: (opts: any, originalOpts: any, jqXHR: JQueryXHR) => any): any; 176 | ajaxPrefilter(dataTypes: string, handler: (opts: any, originalOpts: any, jqXHR: JQueryXHR) => any): any; 177 | 178 | ajaxSetup(options: any): void; 179 | ajaxTransport(dataType: string, handler: (options: JQueryAjaxSettings, originalOptions: JQueryAjaxSettings, jqXHR: JQueryXHR) => JQueryTransport): void; 180 | 181 | get(url: string, data?: any, success?: any, dataType?: any): JQueryXHR; 182 | getJSON(url: string, data?: any, success?: any): JQueryXHR; 183 | getScript(url: string, success?: any): JQueryXHR; 184 | 185 | param(obj: any): string; 186 | param(obj: any, traditional: boolean): string; 187 | 188 | post(url: string, data?: any, success?: any, dataType?: any): JQueryXHR; 189 | 190 | // Callbacks 191 | Callbacks(flags: any): JQueryCallback; 192 | 193 | // Core 194 | holdReady(hold: boolean): any; 195 | 196 | (): JQuery; 197 | (selector: string, context?: any): JQuery; 198 | (element: Element): JQuery; 199 | (elementArray: Element[]): JQuery; 200 | (object: JQuery): JQuery; 201 | (func: Function): JQuery; 202 | (object: {}): JQuery; 203 | 204 | noConflict(removeAll?: boolean): Object; 205 | 206 | when(...deferreds: any[]): JQueryPromise; 207 | 208 | // CSS 209 | css(e: any, propertyName: string, value?: any): any; 210 | css(e: any, propertyName: any, value?: any): any; 211 | cssHooks: { [key: string]: any; }; 212 | 213 | // Data 214 | data(element: Element, key: string, value: any): Object; 215 | 216 | dequeue(element: Element, queueName?: string): any; 217 | 218 | hasData(element: Element): boolean; 219 | 220 | queue(element: Element, queueName?: string): any[]; 221 | queue(element: Element, queueName: string, newQueueOrCallback: any): JQuery; 222 | 223 | removeData(element: Element, name?: string): JQuery; 224 | 225 | // Deferred 226 | Deferred(beforeStart?: (deferred: JQueryDeferred) => any): JQueryDeferred; 227 | 228 | // Effects 229 | fx: { tick: () => void; interval: number; stop: () => void; speeds: { slow: number; fast: number; }; off: boolean; step: any; }; 230 | 231 | // Events 232 | proxy(func: Function, context: any): any; 233 | proxy(context: any, name: string): any; 234 | 235 | // Internals 236 | error(message: any): void; 237 | 238 | // Miscellaneous 239 | expr: any; 240 | fn: any; // Decide how we want to type this 241 | isReady: boolean; 242 | 243 | // Properties 244 | browser: JQueryBrowserInfo; 245 | support: JQuerySupport; 246 | 247 | // Utilities 248 | contains(container: Element, contained: Element): boolean; 249 | 250 | each(collection: any, callback: (indexInArray: any, valueOfElement: any) => any): any; 251 | 252 | extend(deep: boolean, target: any, ...objs: any[]): Object; 253 | extend(target: any, ...objs: any[]): Object; 254 | 255 | globalEval(code: string): any; 256 | 257 | grep(array: any[], func: any, invert: boolean): any[]; 258 | 259 | inArray(value: any, array: any[], fromIndex?: number): number; 260 | 261 | isArray(obj: any): boolean; 262 | isEmptyObject(obj: any): boolean; 263 | isFunction(obj: any): boolean; 264 | isNumeric(value: any): boolean; 265 | isPlainObject(obj: any): boolean; 266 | isWindow(obj: any): boolean; 267 | isXMLDoc(node: Node): boolean; 268 | 269 | makeArray(obj: any): any[]; 270 | 271 | map(array: any[], callback: (elementOfArray: any, indexInArray: any) => any): any[]; 272 | 273 | merge(first: any[], second: any[]): any[]; 274 | 275 | noop(): any; 276 | 277 | now(): number; 278 | 279 | parseHTML(data: string, context?: Element, keepScripts?: boolean): any[]; 280 | parseJSON(json: string): any; 281 | 282 | // This should return an XMLDocument 283 | parseXML(data: string): any; 284 | 285 | queue(element: Element, queueName: string, newQueue: any[]): JQuery; 286 | 287 | trim(str: string): string; 288 | 289 | type(obj: any): string; 290 | 291 | unique(arr: any[]): any[]; 292 | } 293 | 294 | /* 295 | The jQuery instance members 296 | */ 297 | interface JQuery { 298 | // AJAX 299 | ajaxComplete(handler: any): JQuery; 300 | ajaxError(handler: (evt: any, xhr: any, opts: any) => any): JQuery; 301 | ajaxSend(handler: (evt: any, xhr: any, opts: any) => any): JQuery; 302 | ajaxStart(handler: () => any): JQuery; 303 | ajaxStop(handler: () => any): JQuery; 304 | ajaxSuccess(handler: (evt: any, xml: any, opts: any) => any): JQuery; 305 | 306 | serialize(): string; 307 | serializeArray(): any[]; 308 | 309 | // Attributes 310 | addClass(classNames: string): JQuery; 311 | addClass(func: (index: any, currentClass: any) => JQuery): JQuery; 312 | 313 | attr(attributeName: string): string; 314 | attr(attributeName: string, func: (index: any, attr: any) => any): JQuery; 315 | attr(attributeName: string, value: any): JQuery; 316 | attr(map: { [key: string]: any; }): JQuery; 317 | 318 | hasClass(className: string): boolean; 319 | 320 | html(): string; 321 | html(htmlString: string): JQuery; 322 | 323 | prop(propertyName: string): any; 324 | prop(propertyName: string, func: (index: any, oldPropertyValue: any) => any): JQuery; 325 | prop(propertyName: string, value: any): JQuery; 326 | prop(map: any): JQuery; 327 | 328 | removeAttr(attributeName: any): JQuery; 329 | 330 | removeClass(func: (index: any, cls: any) => any): JQuery; 331 | removeClass(className?: string): JQuery; 332 | 333 | removeProp(propertyName: any): JQuery; 334 | 335 | toggleClass(func: (index: any, cls: any, swtch: any) => any): JQuery; 336 | toggleClass(swtch?: boolean): JQuery; 337 | toggleClass(className: any, swtch?: boolean): JQuery; 338 | 339 | val(): any; 340 | val(value: string[]): JQuery; 341 | val(value: string): JQuery; 342 | val(func: (index: any, value: any) => any): JQuery; 343 | 344 | // CSS 345 | css(propertyNames: any[]): string; 346 | css(propertyName: string): string; 347 | css(propertyName: string, value: any): JQuery; 348 | css(propertyName: any, value?: any): JQuery; 349 | 350 | height(): number; 351 | height(value: number): JQuery; 352 | height(func: (index: any, height: any) => any): JQuery; 353 | 354 | innerHeight(): number; 355 | innerWidth(): number; 356 | 357 | offset(): { top: number; left: number; }; 358 | offset(func: (index: any, coords: any) => any): JQuery; 359 | offset(coordinates: any): JQuery; 360 | 361 | outerHeight(includeMargin?: boolean): number; 362 | outerWidth(includeMargin?: boolean): number; 363 | 364 | position(): { top: number; left: number; }; 365 | 366 | scrollLeft(): number; 367 | scrollLeft(value: number): JQuery; 368 | 369 | scrollTop(): number; 370 | scrollTop(value: number): JQuery; 371 | 372 | width(): number; 373 | width(value: number): JQuery; 374 | width(func: (index: any, height: any) => any): JQuery; 375 | 376 | // Data 377 | clearQueue(queueName?: string): JQuery; 378 | 379 | data(key: string, value: any): JQuery; 380 | data(obj: { [key: string]: any; }): JQuery; 381 | data(key?: string): any; 382 | 383 | dequeue(queueName?: string): JQuery; 384 | 385 | queue(queueName?: string): any[]; 386 | queue(queueName: string, newQueueOrCallback: any): JQuery; 387 | queue(newQueueOrCallback: any): JQuery; 388 | 389 | removeData(nameOrList?: any): JQuery; 390 | 391 | // Deferred 392 | promise(type?: any, target?: any): JQueryPromise; 393 | 394 | // Effects 395 | animate(properties: any, options: { duration?: any; easing?: string; complete?: Function; step?: Function; queue?: boolean; specialEasing?: any; }): JQuery; 396 | animate(properties: any, duration?: any, easing?: "linear", complete?: Function): JQuery; 397 | animate(properties: any, duration?: any, easing?: "swing", complete?: Function): JQuery; 398 | animate(properties: any, duration?: any, easing?: string, complete?: Function): JQuery; 399 | 400 | delay(duration: number, queueName?: string): JQuery; 401 | 402 | fadeIn(duration?: any, easing?: "linear", complete?: Function): JQuery; 403 | fadeIn(duration?: any, easing?: "swing", complete?: Function): JQuery; 404 | fadeIn(duration?: any, easing?: string, complete?: Function): JQuery; 405 | fadeIn(duration?: any, complete?: Function): JQuery; 406 | 407 | 408 | fadeOut(duration?: any, easing?: "linear", complete?: Function): JQuery; 409 | fadeOut(duration?: any, easing?: "swing", complete?: Function): JQuery; 410 | fadeOut(duration?: any, easing?: string, complete?: Function): JQuery; 411 | fadeOut(duration?: any, complete?: any): JQuery; 412 | 413 | fadeTo(duration: any, opacity: number, easing?: "linear", complete?: Function): JQuery; 414 | fadeTo(duration: any, opacity: number, easing?: "swing", complete?: Function): JQuery; 415 | fadeTo(duration: any, opacity: number, easing?: string, complete?: Function): JQuery; 416 | fadeTo(duration: any, opacity: number, complete?: Function): JQuery; 417 | 418 | fadeToggle(duration?: any, easing?: "linear", complete?: Function): JQuery; 419 | fadeToggle(duration?: any, easing?: "swing", complete?: Function): JQuery; 420 | fadeToggle(duration?: any, easing?: string, complete?: Function): JQuery; 421 | 422 | finish(queue?: string): JQuery; 423 | 424 | hide(duration?: any, easing?: "linear", callback?: Function): JQuery; 425 | hide(duration?: any, easing?: "swing", callback?: Function): JQuery; 426 | hide(duration?: any, easing?: string, callback?: Function): JQuery; 427 | hide(duration?: any, callback?: Function): JQuery; 428 | 429 | show(duration?: any, easing?: "linear", complete?: Function): JQuery; 430 | show(duration?: any, easing?: "swing", complete?: Function): JQuery; 431 | show(duration?: any, easing?: string, complete?: Function): JQuery; 432 | show(duration?: any, complete?: Function): JQuery; 433 | 434 | slideDown(duration?: any, easing?: "linear", complete?: Function): JQuery; 435 | slideDown(duration?: any, easing?: "swing", complete?: Function): JQuery; 436 | slideDown(duration?: any, easing?: string, complete?: Function): JQuery; 437 | slideDown(duration?: any, complete?: Function): JQuery; 438 | 439 | slideToggle(duration?: any, easing?: "linear", complete?: Function): JQuery; 440 | slideToggle(duration?: any, easing?: "swing", complete?: Function): JQuery; 441 | slideToggle(duration?: any, easing?: string, complete?: Function): JQuery; 442 | slideToggle(duration?: any, complete?: Function): JQuery; 443 | 444 | slideUp(duration?: any, easing?: "linear", complete?: Function): JQuery; 445 | slideUp(duration?: any, easing?: "swing", complete?: Function): JQuery; 446 | slideUp(duration?: any, easing?: string, complete?: Function): JQuery; 447 | slideUp(duration?: any, complete?: Function): JQuery; 448 | 449 | stop(clearQueue?: boolean, jumpToEnd?: boolean): JQuery; 450 | stop(queue?: any, clearQueue?: boolean, jumpToEnd?: boolean): JQuery; 451 | 452 | toggle(showOrHide: boolean): JQuery; 453 | toggle(duration?: any, easing?: "linear", complete?: Function): JQuery; 454 | toggle(duration?: any, easing?: "swing", complete?: Function): JQuery; 455 | toggle(duration?: any, easing?: string, complete?: Function): JQuery; 456 | toggle(duration?: any, complete?: Function): JQuery; 457 | 458 | // Events 459 | bind(eventType: string, preventBubble: boolean): JQuery; 460 | bind(eventType: string, eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 461 | bind(eventType: string, eventData: any, preventBubble: boolean): JQuery; 462 | bind(...events: any[]): JQuery; 463 | 464 | blur(handler: (eventObject: JQueryEventObject) => any): JQuery; 465 | blur(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 466 | 467 | change(handler: (eventObject: JQueryEventObject) => any): JQuery; 468 | change(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 469 | 470 | click(handler: (eventObject: JQueryEventObject) => any): JQuery; 471 | click(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 472 | 473 | dblclick(handler: (eventObject: JQueryEventObject) => any): JQuery; 474 | dblclick(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 475 | 476 | delegate(selector: any, eventType: string, handler: (eventObject: JQueryEventObject) => any): JQuery; 477 | 478 | focus(handler: (eventObject: JQueryEventObject) => any): JQuery; 479 | focus(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 480 | 481 | focusin(handler: (eventObject: JQueryEventObject) => any): JQuery; 482 | focusin(eventData: any, handler: (eventObject: JQueryEventObject) => any): JQuery; 483 | 484 | focusout(handler: (eventObject: JQueryEventObject) => any): JQuery; 485 | focusout(eventData: any, handler: (eventObject: JQueryEventObject) => any): JQuery; 486 | 487 | hover(handlerIn: (eventObject: JQueryEventObject) => any, handlerOut: (eventObject: JQueryEventObject) => any): JQuery; 488 | hover(handlerInOut: (eventObject: JQueryEventObject) => any): JQuery; 489 | 490 | keydown(handler: (eventObject: JQueryEventObject) => any): JQuery; 491 | keydown(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 492 | 493 | keypress(handler: (eventObject: JQueryEventObject) => any): JQuery; 494 | keypress(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 495 | 496 | keyup(handler: (eventObject: JQueryEventObject) => any): JQuery; 497 | keyup(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 498 | 499 | mousedown(handler: (eventObject: JQueryEventObject) => any): JQuery; 500 | mousedown(eventData: any, handler: (eventObject: JQueryEventObject) => any): JQuery; 501 | 502 | mouseevent(handler: (eventObject: JQueryEventObject) => any): JQuery; 503 | mouseevent(eventData: any, handler: (eventObject: JQueryEventObject) => any): JQuery; 504 | 505 | mouseenter(handler: (eventObject: JQueryEventObject) => any): JQuery; 506 | mouseenter(eventData: any, handler: (eventObject: JQueryEventObject) => any): JQuery; 507 | 508 | mouseleave(handler: (eventObject: JQueryEventObject) => any): JQuery; 509 | mouseleave(eventData: any, handler: (eventObject: JQueryEventObject) => any): JQuery; 510 | 511 | mousemove(handler: (eventObject: JQueryEventObject) => any): JQuery; 512 | mousemove(eventData: any, handler: (eventObject: JQueryEventObject) => any): JQuery; 513 | 514 | mouseout(handler: (eventObject: JQueryEventObject) => any): JQuery; 515 | mouseout(eventData: any, handler: (eventObject: JQueryEventObject) => any): JQuery; 516 | 517 | mouseover(handler: (eventObject: JQueryEventObject) => any): JQuery; 518 | mouseover(eventData: any, handler: (eventObject: JQueryEventObject) => any): JQuery; 519 | 520 | mouseup(handler: (eventObject: JQueryEventObject) => any): JQuery; 521 | mouseup(eventData: any, handler: (eventObject: JQueryEventObject) => any): JQuery; 522 | 523 | off(events?: string, selector?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 524 | off(eventsMap: { [key: string]: any; }, selector?: any): JQuery; 525 | 526 | on(events: string, selector?: any, data?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 527 | on(eventsMap: { [key: string]: any; }, selector?: any, data?: any): JQuery; 528 | 529 | one(events: string, selector?: any, data?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 530 | one(eventsMap: { [key: string]: any; }, selector?: any, data?: any): JQuery; 531 | 532 | ready(handler: any): JQuery; 533 | 534 | resize(handler: (eventObject: JQueryEventObject) => any): JQuery; 535 | resize(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 536 | 537 | scroll(handler: (eventObject: JQueryEventObject) => any): JQuery; 538 | scroll(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 539 | 540 | select(handler: (eventObject: JQueryEventObject) => any): JQuery; 541 | select(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 542 | 543 | submit(handler: (eventObject: JQueryEventObject) => any): JQuery; 544 | submit(eventData?: any, handler?: (eventObject: JQueryEventObject) => any): JQuery; 545 | 546 | trigger(eventType: string, ...extraParameters: any[]): JQuery; 547 | trigger(event: JQueryEventObject): JQuery; 548 | 549 | triggerHandler(eventType: string, ...extraParameters: any[]): Object; 550 | 551 | unbind(eventType?: string, handler?: (eventObject: JQueryEventObject) => any): JQuery; 552 | unbind(eventType: string, fls: boolean): JQuery; 553 | unbind(evt: any): JQuery; 554 | 555 | undelegate(): JQuery; 556 | undelegate(selector: any, eventType: string, handler?: (eventObject: JQueryEventObject) => any): JQuery; 557 | undelegate(selector: any, events: any): JQuery; 558 | undelegate(namespace: string): JQuery; 559 | 560 | // Internals 561 | context: Element; 562 | jquery: string; 563 | pushStack(elements: any[]): JQuery; 564 | pushStack(elements: any[], name: any, arguments: any): JQuery; 565 | 566 | // Manipulation 567 | after(func: (index: any) => any): JQuery; 568 | after(...content: any[]): JQuery; 569 | 570 | append(func: (index: any, html: any) => any): JQuery; 571 | append(...content: any[]): JQuery; 572 | 573 | appendTo(target: any): JQuery; 574 | 575 | before(func: (index: any) => any): JQuery; 576 | before(...content: any[]): JQuery; 577 | 578 | clone(withDataAndEvents?: boolean, deepWithDataAndEvents?: boolean): JQuery; 579 | 580 | detach(selector?: any): JQuery; 581 | 582 | empty(): JQuery; 583 | 584 | insertAfter(target: any): JQuery; 585 | insertBefore(target: any): JQuery; 586 | 587 | prepend(func: (index: any, html: any) => any): JQuery; 588 | prepend(...content: any[]): JQuery; 589 | 590 | prependTo(target: any): JQuery; 591 | 592 | remove(selector?: any): JQuery; 593 | 594 | replaceAll(target: any): JQuery; 595 | 596 | replaceWith(func: any): JQuery; 597 | 598 | text(textString: string): JQuery; 599 | text(): string; 600 | 601 | toArray(): any[]; 602 | 603 | unwrap(): JQuery; 604 | 605 | wrap(func: (index: any) => any): JQuery; 606 | wrap(wrappingElement: any): JQuery; 607 | 608 | wrapAll(wrappingElement: any): JQuery; 609 | 610 | wrapInner(func: (index: any) => any): JQuery; 611 | wrapInner(wrappingElement: any): JQuery; 612 | 613 | // Miscellaneous 614 | each(func: (index: any, elem: Element) => any): JQuery; 615 | 616 | get(index?: number): any; 617 | 618 | index(selectorOrElement?: any): number; 619 | 620 | // Properties 621 | length: number; 622 | [x: number]: HTMLElement; 623 | 624 | // Traversing 625 | add(selector: string, context?: any): JQuery; 626 | add(html: string): JQuery; 627 | add(obj: JQuery): JQuery; 628 | add(...elements: any[]): JQuery; 629 | 630 | addBack(selector?: any): JQuery; 631 | 632 | children(selector?: any): JQuery; 633 | 634 | closest(selector: string): JQuery; 635 | closest(selector: string, context?: Element): JQuery; 636 | closest(obj: JQuery): JQuery; 637 | closest(element: any): JQuery; 638 | closest(selectors: any, context?: Element): any[]; 639 | 640 | contents(): JQuery; 641 | 642 | end(): JQuery; 643 | 644 | eq(index: number): JQuery; 645 | 646 | filter(selector: string): JQuery; 647 | filter(func: (index: any) => any): JQuery; 648 | filter(obj: JQuery): JQuery; 649 | filter(element: any): JQuery; 650 | 651 | find(selector: string): JQuery; 652 | find(element: any): JQuery; 653 | find(obj: JQuery): JQuery; 654 | 655 | first(): JQuery; 656 | 657 | has(selector: string): JQuery; 658 | has(contained: Element): JQuery; 659 | 660 | is(selector: string): boolean; 661 | is(func: (index: any) => any): boolean; 662 | is(obj: JQuery): boolean; 663 | is(element: any): boolean; 664 | 665 | last(): JQuery; 666 | 667 | map(callback: (index: any, domElement: Element) => any): JQuery; 668 | 669 | next(selector?: string): JQuery; 670 | 671 | nextAll(selector?: string): JQuery; 672 | 673 | nextUntil(selector?: string, filter?: string): JQuery; 674 | nextUntil(element?: Element, filter?: string): JQuery; 675 | 676 | not(selector: string): JQuery; 677 | not(func: (index: any) => any): JQuery; 678 | not(obj: JQuery): JQuery; 679 | not(element: any): JQuery; 680 | 681 | offsetParent(): JQuery; 682 | 683 | parent(selector?: string): JQuery; 684 | 685 | parents(selector?: string): JQuery; 686 | 687 | parentsUntil(selector?: string, filter?: string): JQuery; 688 | parentsUntil(element?: Element, filter?: string): JQuery; 689 | 690 | prev(selector?: string): JQuery; 691 | 692 | prevAll(selector?: string): JQuery; 693 | 694 | prevUntil(selector?: string, filter?: string): JQuery; 695 | prevUntil(element?: Element, filter?: string): JQuery; 696 | 697 | siblings(selector?: string): JQuery; 698 | 699 | slice(start: number, end?: number): JQuery; 700 | } 701 | 702 | declare var jQuery: JQueryStatic; 703 | declare var $: JQueryStatic; 704 | -------------------------------------------------------------------------------- /WebContent/readme.txt: -------------------------------------------------------------------------------- 1 | /** 2 | *@Version:1.0 3 | *@DEMO:typescript 4 | *@Date:2015-7-28 下午12:13:25 5 | *@Author:liangjilong 6 | *@Email:jilongliang@sina.com 7 | *@Weibo:http://weibo.com/jilongliang 8 | *@Description:readme文件 9 | */ 10 | 1、详细安装文章请看 11 | http://blog.csdn.net/jilongliang/article/details/21942911 12 | 13 | 2、TypeScript官方手册 14 | http://www.typescriptlang.org/Handbook 15 | 16 | 3、TypeScript官方例子 17 | https://github.com/Microsoft/TypeScriptSamples 18 | http://typescript.codeplex.com/ 19 | 20 | 4、注意TypeScript的ts文件会多处有红色的XX,并不代表它有错误,如果是Myeclipse的话可以在 21 | Myeclipse--->> Exclude From Validation忽略红色的问题 22 | 23 | 5、看TypeScript例子源碼情況.ts文件,javascript源碼是.js 24 | 25 | 6、参考博客.. 26 | http://ju.outofmemory.cn/entry/954 27 | http://www.oschina.net/question/12_72250 28 | http://www.cnblogs.com/whitewolf/p/4103328.html 29 | 30 | 7、注意事项: 31 | A、必须选择ECMAScript target version ES3或ES5,选择ES6版本太高,生成的js文件会有class关键字 32 | 33 | B、eclipse设置默认.ts文件格式是TypeScript 34 | Window--->General-Editor--->File Associatior-->*.ts选择默认TypeScript 35 | 36 | C、 不要勾选Enable typeScript Builder,勾选了这个它不会帮你生成js文件 37 | 勾选Disable typeScript Builder即可 38 | 39 | D、找到官方的jquery.d.ts文件拷贝到工程项目,在学习开发的时候会引用到. 40 | 41 | 42 | 不使用Module,如果我们在typescript使用了module函数,则生成的代码在浏览器端执行时,需要有一些script loader的支持。 43 | 对于浏览器端代码,我们一般生成amd风格的代码,所以需要找一个支持amd的库放在前端。这样的库有很多 44 | 45 | 46 | --------------------------------------------------------------------------------