xiao17

es6 的这种写法是哪个知识点?

  •  1
     
  •   xiao17 · Aug 21, 2015 · 3821 views
    This topic created in 3949 days ago, the information mentioned may be changed or developed.

    如题:

    'use strict';
    
    export default function hostnameFromUrl (str: string ): string {
        let url = document.createElement ('a');
        url.href = /^(f|ht )tps?:\/\//i.test (url ) ? 'http://' + str : str;
        return url.hostname;
    }
    

    上面这种写法是 ES6 的哪个知识点? 是 bable.js 解析器支持的? 貌似没有见过呢.

    8 replies    2015-08-21 20:24:23 +08:00
    timonwong
        1
    timonwong  
       Aug 21, 2015
    非 ES ,倒是符合 TypeScript
    hvsy
        2
    hvsy  
       Aug 21, 2015
    ES2015 就是 ES6
    export default 这个是跟 nodejs 的 module.export 一样
    str : string 是参数类型
    let 是新的关键跟 var 类似.只是 let 和 var 变量的作用域不同
    这个是 bable.js 支持的特性列表:http://babeljs.io/docs/learn-es2015/
    xiao17
        3
    xiao17  
    OP
       Aug 21, 2015
    @hvsy 恩 懂了,谢谢.
    ChefIsAwesome
        4
    ChefIsAwesome  
       Aug 21, 2015 via Android
    现在到处都是用 es6 写法的。特别是 react 圈子的人。每次看到 import / class 都蛋疼
    yoa1q7y
        5
    yoa1q7y  
       Aug 21, 2015
    @ChefIsAwesome 逼格满满
    performonkey
        6
    performonkey  
       Aug 21, 2015
    @yij ,静态类型检测的可能是用的这个: http://flowtype.org/
    xiao17
        7
    xiao17  
    OP
       Aug 21, 2015
    @ChefIsAwesome 然而就是在做 react 项目遇到的.
    xiao17
        8
    xiao17  
    OP
       Aug 21, 2015
    @yoa1q7y 然而 react + reflux + webpack + es6 确实不错.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2796 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 12:40 · PVG 20:40 · LAX 05:40 · JFK 08:40
    ♥ Do have faith in what you're doing.