函数重载和编译器有关系

缘起

先看一段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

你可能感兴趣的:(函数重载和编译器有关系)