1

Building a site with a bunch of different card games. Each game has its own controller, but there are some functions that are duplicated in all of the games. Is it possible to extract the following code from all of these games into one game. It seems like the inheritance in JavaScript is wonky enough that that might not be useful? I don't know.

setScope = function(obj) {
  $scope.game = obj.game;
  $scope.activePlayer = obj.active_player;
  $scope.players = obj.players;
}

1 Answer 1

1

in angular you could inherit on this way (it sounds like trait) :

parent

app.controller('gameCtrl',[function(){
    $scope.init = function(obj) {
        $scope.game = obj.game;
        $scope.activePlayer = obj.active_player;
        $scope.players = obj.players;
    };
}]);

* child *

app.controller('game1Ctrl', [$controller, function($controller){
    $controller('gameCtrl',{$scope:$scope});

    var obj  = {};
    $scope.init(obj);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.