SOURCE

var Site = /** @class */ (function () {
    function Site() {
    }
    Site.prototype.name = function () {
        console.log("Runoob");
    };
    return Site;
}());
var obj = new Site();
obj.name();

function greet() {
    return "Hello World";
}
function caller() {
    var msg = greet(); // 调用 greet() 函数 
    console.log(msg);
}
// 调用函数
caller();

var global_num = 12; // 全局变量
var Numbers = /** @class */ (function () {
    function Numbers() {
        this.num_val = 13; // 实例变量
    }
    Numbers.prototype.storeNum = function () {
        var local_num = 14; // 局部变量
    };
    Numbers.sval = 10; // 静态变量
    return Numbers;
}());
console.log("全局变量为: " + global_num);
console.log(Numbers.sval); // 静态变量
var obj = new Numbers();
console.log("实例变量: " + obj.num_val);


// var num:number = 5;
// var i:number;
// var factorial = 1;
// for(i = num;i >= i;i--){
//     factorial *= 1;
// }
// console.log(factorial);

var j;
var n = "a b c";
for(j in n){
    console.log(n[j]);
}

var num = 5;
var factor = 1;
while(num >= 1){
    factor = factor * num;
    num--;
}
console.log("5的阶乘为:" + factor);

var num = 5;
var n = 10;
do{
    console.log(n);
    n--;
}while(n>=0);


function greet(){
    return "Hello World";
}

function caller(){
    var msg = greet();
    console.log(msg);
}
caller();


// function add(x:number,y:number):number{
//     retrun x + y;
// }
// console.log(add(1,2))
function add(x,y){
    return x + y;
}
console.log(add(1,2))

var c = 10;
function fun(x)
{
    x += 1;
    console.log(x);
}
fun(c);
console.log(c);

// function buildName(firstName:string,lastName:string){
//     return firstName + " " + lastName;
// }
// let result1 = buildName("Bod");
// let result2 = buildName("Bod","Adams","Sr.");
// let result3 = buildName("Bod","Adams");

// function buildName(firstName:string,lastName?:string){
//     if(lastName)
//         return firstName + " " + lastName;
//     else
//         return firstName;
// }
// let result1 = buildName("Bod");
// let result2 = buildName("Bod","Adams","Sr.");
// let result3 = buildName("Bod","Adams");

// function calculate_discount(price:number,rate:number = 0.5){
//     var discount = price * rate;
//     console.log("计算结果:",discount);
// }
// calculate_discount(1000);
// calculate_discount(1000,0.30);

function  calculate_discount(price,rate){
    if(rate == void 0){rate = 0.50;}
    var discount = price* rate;
    console.log("计算结果:"+ discount);
}
calculate_discount(1000);
calculate_discount(1000,0.30);


// function buildName(firstName:string,...restOfName:string[]){
//     return firstName + " " + restOfName.join(" ");
// }

// let employeeName = buildName("Joseph","Samuel","Lucas","MacKinzie");

// function addNumbers(...nums:number[]){
//     var i;
//     var sum:number = 0;
//     for(i = 0;i < nums.length;i++){
//         sum = sum + nums[i];
//     }
//     console.log("和为:",sum)
// }
// addNumbers(1,2,3)
// addNumbers(10,10,10,10,10)

function addNumbers(){
    var nums =[];
    for(var _i = 0;_i < arguments.length;_i++){
        nums[_i] = arguments[_i];
    }
    var i;
    var sum =0;
    for(i =0 ;i <nums.length;i++){
        sum = sum + nums[i];
    }
    console.log("和为:"+ sum);
}

addNumbers(1,2,3);
addNumbers(10,10,10,10,10);

var msg = function(){
    return "hello world";
}
console.log(msg())

var msg = function(){
    return "hello world";
}
console.log(msg());

// var res = function(a:number,b:number){
//     return a*b;
// }
// console.log(res(12,2))

var res = function(a ,b)
{
    return a* b;
}
console.log(res(12,2));

(function (){
    var x = "Hello!!";
    console.log(x)
})();
// (function (){
//     var x = "aa";
//     console.log(x)
// })()
(function () { 
    var x = "Hello!!";   
    console.log(x)    
})();

var myFunction = new Function("a","b","return a*b");
var x = myFunction(4,3);
console.log(x);

var myFunction = new Function("a","b","return a*b");
var x = myFunction(4,3);
console.log(x);

var myFunction = new Function("a","b","return a*b");
var x = myFunction(4,3);
console.log(x);

function factorial(number){
    if(number <= 0){
        return 1;
    }else{
        return (number * factorial(number - 1));
    }
};
console.log(factorial(6));

function factor(number){
    if(number <= 0){
        return 1;
    }
    else{
        return (number * factorial(number - 1));
    }
};
console.log(factorial(6));

// var foo = (x:number)=>10 + x
// console.log(foo(100))
var foo = function (x) {return 10 + x;};
console.log(foo(100));

// var foo = (x:number)=>{
//     x = 10 + x;
//     console.log(x);
// };
// foo(100);

var foo = function(x){
    x = 10 + x;
    console.log(x);
};
foo(100);

var func = function (x){
    if(typeof x =="number"){
        console.log(x + " 是一个数字");
    }
    else if(typeof x == "string"){
        console.log(x + " 是一个字符串");
    }
};
func(12);
func("Tom");


// var disp = function(){
//     console.log("调用函数");
// };
// disp();

function disp(x,y){
    console.log(x);
    console.log(y);
}
disp("abc");
disp(1,"xyz");

var suits = ["hearts","spades","clubs","diamonds"];
//实现签名
function greet1(person){
    if(typeof person == 'string'){
        return "Hello, ".concat(person,"!");
    }
    else if(Array.isArray(person)){
        return person.map(function (name) {return "Hello, ".concat(name, "!");})
    }
    throw new Error('Unable to greet');
};
console.log(greet1(suits[0]));
console.log(greet1(suits));

let myMap = new Map([
    ["key1","value1"],
    ["key2","value2"]
]);

let nameSiteMapping = new Map();
nameSiteMapping.set("Goole",1);
nameSiteMapping.set("Runoob",2);
nameSiteMapping.set("Taobao",3);

// console.log(nameSiteMapping.get("Runoob"));
// console.log(nameSiteMapping.has("Taobao"));
// console.log(nameSiteMapping.has("Zhihu"));

// console.log(nameSiteMapping.size);

// console.log(nameSiteMapping.delete("Runoob"));
// console.log(nameSiteMapping);
for( let key of nameSiteMapping.keys()){
    console.log(key);
}

for(let value of nameSiteMapping.values()){
    console.log(value);
}

for(let entry of nameSiteMapping.entries()){
    console.log(entry[0],entry[1]);
}

for(let [key,value] of nameSiteMapping){
    console.log(key,value);
}


var mytuple = [10,"hello","world","typescript"];
console.log("添加前元素的个数:" + mytuple.length);
mytuple.push(12);
console.log("添加后元素个数:" + mytuple.length);
console.log("删除前元素个数:" + mytuple.length);
console.log(mytuple.pop() + "元素从元组中删除");
console.log("删除后元素个数:" + mytuple.length);

var mytuple = [10,"Runoob","Taobao","Goole"];
console.log("元组的第一个元素为:" + mytuple[0]);
//更新元组元素
mytuple[0] = 121;
console.log("元组中的第一个元素更新为:"+ mytuple[0]);

var a = [10,"Runoob"];
var b = a[0],c = a[1];
console.log(b);
console.log(c);


var sites = {
    site1:"Runoob",
    site2:"Google"
};

var invokesites = function(obj){
    console.log("site1 :" + obj.site1);
    console.log("site2 :" + obj.site2);
};
invokesites(sites);


var person = (function (){
    function person(){

    }
    return person;
}()
);

var Car = (function ()
{
    function Car(engine){
        this.engine = engine;
    }

    Car.prototype.disp = function()
    {
        console.log("函数中显示发动机型号:" + this.engine);
    }
    return Car;
}());
var obj = new Car("XXSY1");
console.log("读取发动机型号: " +obj.engine);
obj.disp();

// class Shape{
//     Area:number

//     constructor(a:number){
//         this.Area = a;
//     }
// }

// calss Circle extends Shape{
//     disp():void{
//         console.log("圆的面积: " + this.Area);
//     }
// }
// var obj = new Circle(223);
// obj.disp();

var __extends = (this && this.__extends) || (function (){
    var extendStatics = function(d,b){
        extendStatics = Object.setPrototypeOf ||
        ({__proto__:[]} instanceof Array && function(d,b){d.__extends = b;}) ||
        function (d,b) {
            for(var p in b)
            {
                if(b.hasOwnProperty(p) )
                {
                    d[p] = b[p];
                }
            }
        }
        return extendStatics(d,b);
    };

    return function(d,b)
    {
        extendStatics(d,b);
        fucntion __() {this.constructor  = d;}
    }
})
console 命令行工具 X clear

                    
>
console