Typescript 中 AngularJS 控制器的实例与原型方法

Instance vs Prototype Methods for AngularJS Controllers in Typescript

如果我不打算继承我的控制器类,将 AngularJS 控制器的方法定义为原型方法与实例方法之间有什么区别吗?

我有 C# 背景,更习惯于定义原型方法。我也喜欢保持构造函数简短。

但是,我看到的大多数 AngularJS 示例都是在实例级别定义方法。

module Test {
    angular
        .module("app")
        .controller("controller",
        ["$scope", MyController]);

    export class MyController {

        public Function1: () => {}

        constructor(private $scope: IMyScope) {
            //instance
            this.Function1() = () => {
                alert("Hello 1!");
            }
        }
    }

    //prototype
    public Function2(): void {
        alert("Hello 2!");
    }

}

If I don't intend to inherit my controller class, is there any difference between defining an AngularJS Controller's methods as prototype methods over instance methods?

实例方法会影响性能。除此之外,使用它们完全没问题。我只使用原型成员。

此视频解释了您可能想要使用实例方法的原因:https://m.youtube.com/watch?v=tvocUcbCupA(主要是为了捕捉这一点)