美文网首页
ES6 => 函数的使用

ES6 => 函数的使用

作者: ZWalter | 来源:发表于2016-12-21 16:16 被阅读0次

    在使用d3时,在g标签下面同时构造两个相同的line时,发现使用=> 函数报错。

    slider.append("line")
    .attr("x1",sliderScale.range([0]).attr("x2",sliderScale.range()[1])
    .select(function() { return this.parentNode.appendChild(this.cloneNode(true)); })
    // select( () => this.parentNode.appendChild(this.cloneNode(true)) ) 报错
    // console.log 上面的 this 出来的是 
    // Window {external: Object, chrome: Object, document: document, d3: Object, speechSynthesis: SpeechSynthesis…}
    

    特别注意使用 => 函数时this指针的运用。
    参考下面的文档:
    => 的使用 http://blog.csdn.net/itpinpai/article/details/52182093
    => 中this指针的测试 https://imququ.com/post/arrow-function-in-es6.html

    相关文章

      网友评论

          本文标题:ES6 => 函数的使用

          本文链接:https://www.haomeiwen.com/subject/iemqvttx.html