你知道,在AngularJS中,大部分逻辑都基于$scope对象:
在这种情况下,我找不到让angularjs与之配合的解决方案。
是否可能让angularjs与原型一起工作,以便它可以与haxe类系统(以及其他支持类的语言,如coffeescript/typescript)一起使用?
function Ctrl($scope) {
$scope.name = "Freewind";
$scope.hello = function() {
alert($scope.name);
}
$scope.method1 = function() {}
$scope.method2 = function() {}
$scope.method3 = function() {}
$scope.method4 = function() {}
$scope.method5 = function() {}
}
现在我正在使用Haxe生成AngularJS代码,如果我的代码是这样的,则可以正常工作:
class Ctrl {
public function new(scope:Scope) {
scope.name = "Freewind";
scope.hello = function() {
alert(scope.name);
}
scope.method1 = function() {}
scope.method2 = function() {}
scope.method3 = function() {}
scope.method4 = function() {}
scope.method5 = function() {}
}
}
typedef Scope = {
name:String,
hello:Void->Void,
method1: Void->Void,
method2: Void->Void,
method3: Void->Void,
method4: Void->Void,
method5: Void->Void
}
但我希望从Haxe的类系统中受益(代码可能更简单、更清晰),像这样声明:
class Scope {
public var name:String;
public function hello() {}
public function method1() {}
public function method2() {}
public function method3() {}
public function method4() {}
public function method5() {}
}
然后找到一种方法将 Scope
类与 angularjs 的 $scope
关联起来。
但是,从 Haxe 生成的 Scope
使用原型:
Scope = function();
Scope.prototype.name = "something";
Scope.prototype.hello = function() {}
Scope.prototype.method1 = function() {}
Scope.prototype.method2 = function() {}
Scope.prototype.method3 = function() {}
Scope.prototype.method4 = function() {}
Scope.prototype.method5 = function() {}
在这种情况下,我找不到让angularjs与之配合的解决方案。
是否可能让angularjs与原型一起工作,以便它可以与haxe类系统(以及其他支持类的语言,如coffeescript/typescript)一起使用?