AngularJS 控制器是函数还是 class?

Is an AngularJS Controller a function or a class?

根据 AngularJS ng-controller 文档:https://docs.angularjs.org/api/ng/directive/ngController, ng-controller "attaches a controller class to the view". According to the AngularJS Controllers documentation: https://docs.angularjs.org/guide/controller,它说:"When a Controller is attached to the DOM via the ng-controller directive, Angular will instantiate a new Controller object"

根据我上面的阅读,控制器是 class。

书"AngularJS Up and Running O'Reily"(强烈推荐学习AngularJS的书)第17页说:"Controllers in AngularJS are our workhorse, the JavaScript FUNCTIONS that perform or trigger the majority of our UI-oriented work."

据我了解,AngularJS 控制器是 class 类,而不是函数。为什么本书在这里将它们称为 JavaScript 函数?

Javascript 没有 类,因为它使用 prototype-based inheritance. ES6 Classes 只是可以与 new 运算符一起使用的函数,用于将新对象初始化为其原型.