3 ms·
If I remember correctly, AngularJS 1.x would use it for dependency injection.
by Nullabillity 7y ago
If I remember correctly, AngularJS 1.x would use it for dependency injection.
- nkozyra 7y agoHow so? Were these eval()ed by Angular? I don't follow what it would use function strings for determining missing - presumably - polyfills that you couldn't do in better ways.
- matsemann 7y agoIn angular 1, if you had a function on the form myApp.controller('MyCtrl', function($myCoolService) { //... }); Angular would see that you are looking for a parameter named myCoolService, see if it already has it, and then inject it when calling your controller. This of course broke in various ways with minification when the parameter names were mangled. So one had the opportunity to use "array syntax", requesting a dependency by a string. Or use a preprocessor in the build script adding the array syntax before minifying.
- wging 7y agoDid it by any chance pull parameter names out by using a magic-number index into the function text? If so, that'd be broken by the 'function /* a comment */ foo () {}' change in the article (and might be what I remember having seen a long time ago). Glad I don't have to deal with that sort of thing. Does Angular 2 do it the same way?