$scope.$evalAsync() vs. $timeout() In AngularJS

Sometimes, in an AngularJS application, you have to explicitly tell AngularJS when to initiate it’s $digest() lifecycle (for dirty-data checking). This requirement is typically contained within a Directive; but, it may also be in an asynchronous Service. Most of the time, this can be easily accomplished with the $scope.$apply() method. However, some of the time,…

javascript bind vs apply/call

When you want that function to later be called with a certain context, useful in events. Call/apply call the function immediately, whereas bind returns a function that when later executed will have the correct context set for calling the original function. This way you can maintain context in async callbacks, and events. I do this a lot:…

How angular js works

1 bootstrap flow: http://java.dzone.com/articles/how-angularjs-works-%E2%80%93 angularInit method which checks for ng-app module bootstrap method which is invoked once an ng-app module is found. Following are key invocations from within bootstrap method: createInjector method which returns dependency injector. On dependency injector instance, invoke method is called. For example if myModule has ‘greeter’ dependency. we get it like…

javascript apply, call and constuctor

Let’s first create a simple function that we will be using through the rest of this post. This function will just return an array with the current value ofthis and the two supplied arguments. <script type=“text/javascript”> function makeArray(arg1, arg2){     return [ this, arg1, arg2 ]; } </script> Most common way, unfortunately, global function calls When we are learning JavaScript we learn how to define…