如何在不收到语法错误的情况下将 this.variable 传递给 (Angular)JS 函数?

How to pass this.variable to a (Angular)JS function without receiving a syntax error?

这是我的 AngulsrJS 代码:

angular.module("UserApp", ["BaseApp"])
    .controller("MainCtrl", ["$http", "$window", "$location", "BaseService", function($http, $window, $location, BaseService) {

var self = this;
self.username = $location.path().substr($location.path().lastIndexOf('/') + 1);

self.watch = function(self.username) {
    BaseService.watch(self.username, function() {
        // more code
    });
};

当我 运行 这段代码时,我得到一个指向第 self.watch = function(self.username) { 行的错误,错误说:

Uncaught SyntaxError: Unexpected token .

知道如何将 self.username 作为参数传递给函数而不会出现错误吗?

函数() {

还是会完成你想要的

只需从函数定义中删除属性:

self.watch = function() {
  BaseService.watch(self.username, function() {
    // more code
});

};