函数重载和编译器有关系

缘起

先看一段jsx代码

class Point {
    var x = 0;
    var y = 0;

    function constructor() {
    }

    function constructor(x : number, y : number) {
        this.set(x, y);
    }

    function constructor(other : Point) {
        this.set(other);
    }

    function set(x : number, y : number) : void {
        this.x = x;
        this.y = y;
    }

    function set(other : Point) : void {
        this.set(other.x, other.y);
    }
}

其中有这么一段话:

The Point#set() functions are also overloaded and the compiler know how to call the correct one.

其中说了编译器将会(根据传参不同)知道去调用哪个方法。

Inspire the curiosity

这引起了我对于编译原理以及jsx的编译实现的好奇

参考文献

https://jsx.github.io/doc/tutorial.html

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,401评论 0 23
  • 做从未做的事,叫成长; 做不愿做的事,叫改变; 做不敢做的事,叫突破。 在学习中成长,在正向里改变,在尝试时突破,...
    殇官婉儿阅读 890评论 0 0
  • 一辈子可以太长一辈子可以太短…你的一辈子太长还是太短…等下班…等
    庐山话画阅读 1,800评论 0 0
  • “木晨哥哥今天走了,姑姑说,他要去好远好远的地方。我哭了,我舍不得他啊!”小木清合上了那本心爱的日记本,望向了...
    钟情楚乔阅读 3,308评论 0 2