Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

repl with context #49

Open
bunions1 opened this issue Aug 2, 2014 · 1 comment
Open

repl with context #49

bunions1 opened this issue Aug 2, 2014 · 1 comment

Comments

@bunions1
Copy link

bunions1 commented Aug 2, 2014

It is often very useful to be able to control the scope/context that repl statements will be evaluated in. For instance when developing an angular controller you probably want to have access to your dependency injected variables. There doesn't seem to be an official way to do that so I thought I'd share a hack that seems to work.

Place the line: skewer.globalEval = function(expression) {return eval(expression);}
where you want your context, kind of like a debugger; statement. For instance:

angular.module('my-app').controller('MainCtrl', function ($scope, $http) { 
    skewer.globalEval = function(expression) {return eval(expression);}
    ....
  }

Now from the prompt you can easily access your $scope variables and such
js> alert($scope.someVar);

@skeeto
Copy link
Owner

skeeto commented Aug 7, 2014

What's going on here is you've changed the indirect eval in globalEval into a direct eval. That's an interesting hack. It may be worth formally encoding this as a mode of operation in Skewer.

The consequence is that you won't be able to make any more global definitions (though that won't matter much in an Angular app) and you'll suffer some degraded performance (direct eval causes deoptimization).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants