• TS 函数解析


    ------------------------------------------------------------------------------------
    函数传参:
    
    //let myAdd: (baseValue:number, increment:number) => number = function(x: number, y: number): number { return x + y; };
    
    enum EventType { Mouse, Keyboard }
    
    interface Event {
        timestamp: number;
    }
    interface MouseEvent extends Event {
        x1: number;
        y1: number;
    }
    interface KeyEvent extends Event {
        keyCode: number
    }
    function listenEvent(eventType: EventType, handler: (nnnnnnnnnn: Event) => string) {
        handler(null);
        return null;
    }
    function listenEvent1(eventType: EventType, handler: (nnnnnnnnnn: string) => string) {
        handler(null);
        return null;
    }
    function listenEvent2(eventType: EventType, handler: (nnnnnnnnnn: Event) => void) {
        handler(null);
        return null;
    }
    function  f(x:string){//(从js来看)声明定义了一个函数
        return "vvv";
    }
    function ff(x:string):string{//声明了一个函数,
        return "vvv";
    }
    var f1 = (x:string) => { //声明定义了一个函数
        return x;
    }
    var f11 : (x:string) => string;  //函数类型
    
    var f111 = (x:string) => { //声明定义了一个函数
        return (x) => {return x}
    }
    var f2 = () => {  //声明定义了一个函数
        console.log("1223");
        return "sss";
    }
    var f22 = () => null;
    
    listenEvent1( EventType.Keyboard, f111("sss")  ); //f111("sss") 使用的是返回值
    //() => {console.log("1223");console.log("4456");return "1111";}  是定义了一个函数,传的是函数的定义,函数调用的时候才会传真实参数,
    listenEvent(EventType.Keyboard, (e: MouseEvent) => {console.log("1223");console.log("4456");return "1111";}     );
    
    listenEvent2(EventType.Keyboard, (e: MouseEvent) => null    );
    
    listenEvent(EventType.Mouse, <(e: Event) => null> (  (e: MouseEvent,s:number) => console.log('e.x' + ',' + 'e.y') )  );
    -------------------js 解析 ----------
    //let myAdd: (baseValue:number, increment:number) => number = function(x: number, y: number): number { return x + y; };
    var EventType;
    (function (EventType) {
        EventType[EventType["Mouse"] = 0] = "Mouse";
        EventType[EventType["Keyboard"] = 1] = "Keyboard";
    })(EventType || (EventType = {}));
    function listenEvent(eventType, handler) {
        handler(null);
        return null;
    }
    function listenEvent1(eventType, handler) {
        handler(null);
        return null;
    }
    function listenEvent2(eventType, handler) {
        handler(null);
        return null;
    }
    function f(x) {
        return "vvv";
    }
    function ff(x) {
        return "vvv";
    }
    var f1 = function (x) {
        return x;
    };
    var f11; //函数类型
    var f111 = function (x) {
        return function (x) { return x; };
    };
    var f2 = function () {
        console.log("1223");
        return "sss";
    };
    var f22 = function () { return null; };
    listenEvent1(EventType.Keyboard, f111("sss")); //f111("sss") 使用的是返回值
    //() => {console.log("1223");console.log("4456");return "1111";}  是定义了一个函数,传的是函数的定义,函数调用的时候才会传真实参数,
    listenEvent(EventType.Keyboard, function (e) { console.log("1223"); console.log("4456"); return "1111"; });
    listenEvent2(EventType.Keyboard, function (e) { return null; });
    listenEvent(EventType.Mouse, (function (e, s) { return console.log('e.x' + ',' + 'e.y'); }));
    ----------------------------------------------------------
  • 相关阅读:
    Uva 10494 If We Were a Child Again
    01 words & sentences BYOD
    Uva 465 Overflow
    354E
    MySQL/mariadb从删库到跑路——备份
    MySQL/mariadb知识点——日志记录(2)二进制日志
    MySQL/mariadb知识点——日志记录(1)
    MySQL/mariadb知识点——函数
    MySQL/mariadb知识点——数据库变量
    MySQL/mariadb知识点——事务Transactions
  • 原文地址:https://www.cnblogs.com/yaowen/p/7217603.html
Copyright © 2020-2023  润新知