When working with AngularJS, the majority of logic is typically based on the $scope
:
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() {}
}
Now, I am utilizing Haxe to generate AngularJS code. It functions correctly when my code is structured like:
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
}
However, I am interested in leveraging Haxe's class system to simplify and clarify the code, like so:
class Scope {
public var name:String;
public function hello() {}
public function method1() {}
public function method2() {}
public function method3() {}
public function method4() {}
public function method5() {}
}
Subsequently, the challenge arises when attempting to associate the Scope
class with the $scope
in AngularJS.
The generated Scope
from Haxe utilizes prototypes:
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() {}
In this scenario, a solution to make AngularJS compatible with it is not readily apparent.
Is it feasible to adapt AngularJS to work with prototypes, enabling compatibility with Haxe's class system (as well as other languages like Coffeescript/Typescript that support classes)?