zoukankan      html  css  js  c++  java
  • xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

    classes & public shorthand

    Also of note, the use of public on arguments to the constructor is a shorthand that allows us to automatically create properties with that name.

    http://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html#classes

    with public

    
    class Student {
        fullName: string;
        constructor(public firstName: string, public middleInitial: string, public lastName: string) {
            this.fullName = firstName + " " + middleInitial + " " + lastName;
        }
    }
    interface Person {
        firstName: string;
        lastName: string;
    }
    function hello(person: Person) {
        // return "Hello, " + person.firstName + " " + person.lastName;
        let {
            firstName,
            lastName,
        } = person;
        return `Hello, ${firstName} ${lastName}`;
    }
    
    let student = new Student("xgqfrms", "X.", "webgeeker");
    let log = console.log;
    log(student.firstName);
    log(student.middleInitial);
    log(student.lastName);
    log(hello(student));
    // document.body.innerHTML = hello(student);
    
    

    no public

    
    class Student {
        fullName: string;
        firstName: string;
        middleInitial: string;
        lastName: string;
        /// no public
        constructor(firstName: string, middleInitial: string, lastName: string) {
            this.firstName = firstName;
            this.middleInitial = middleInitial;
            this.lastName = lastName;
            this.fullName = firstName + " " + middleInitial + " " + lastName;
        }
    }
    interface Person {
        firstName: string;
        lastName: string;
    }
    function hello(person: Person) {
        // return "Hello, " + person.firstName + " " + person.lastName;
        let {
            firstName,
            lastName,
        } = person;
        return `Hello, ${firstName} ${lastName}`;
    }
    
    let student = new Student("xgqfrms", "X.", "webgeeker");
    let log = console.log;
    log(student.firstName);
    log(student.middleInitial);
    log(student.lastName);
    log(hello(student));
    // document.body.innerHTML = hello(student);
    
    
    
  • 相关阅读:
    移动端开发rem布局之less+媒体查询布局的原理步骤和心得
    前端实现文件下载方式总汇
    如何能提高CSS编写技巧?提高Web前端开发效率
    常用的CSS命名规则
    CSS背景background
    CSS盒子模型
    简单的树形菜单如何写?
    彻底掌握css动画【transition】
    首页白屏优化实践
    我来聊聊面向模板的前端开发
  • 原文地址:https://www.cnblogs.com/xgqfrms/p/10983984.html
Copyright © 2011-2022 走看看