【发布时间】:2015-07-02 03:27:22
【问题描述】:
我在 Angular.js 模块中有这个对象声明:
$scope.test=function(){
};
$scope.test.prototype.push = function(data) {
return data;
};
我这样称呼它:
var a = $scope.test.push(1);
console.error(a);
但我得到这个错误:
Error: undefined is not a function (evaluating '$scope.test.push(1)')
为什么我无法访问通过Prototype 添加到我的对象的方法?
【问题讨论】:
-
test可以从您使用test作为构造函数创建的对象访问,而不是从函数对象本身访问,除非您使用$scope.test.prototype.push(1);,这很奇怪。如果你愿意,你可以将push函数直接添加到$scope.test函数中,但我不确定你到底想要什么。 -
你可能想要
var a = new $scope.test.push(1);,如果是这样,约定是用大写字母命名Test
标签: javascript angularjs node.js