angularjs filter on array

Use property in input’s ng model Filter is used for selecting a subset of a give array. The requirements for a filter are an array to be filtered and the predicate based on which the array need to be filtered. The predicate could be as simple as a string and let’s try filtering using a…

Immediately Invoked Function Expressions (IIEF)

(How Immediately Invoked Function Expressions Work and When to Use Them) IIFE (pronounced “Iffy”) is an abbreviation for Immediately Invoked Function Expression, and the syntax looks like this: (function () { // Do fun stuff​ } )() It is an anonymous function expression that is immediately invoked, and it has some particularly important uses in…

angularjs scope inheritence primitive object

JavaScript Prototypal Inheritance It is important to first have a solid understanding of JavaScript prototypal inheritance, especially if you are coming from a server-side background and you are more familiar with classical inheritance. So let’s review that first. Suppose parentScope has properties aString, aNumber, anArray, anObject, and aFunction. If childScope prototypically inherits from parentScope, we…

angular js module call order run() config()

Here’s the calling order: app.config() app.run() directive’s compile functions (if they are found in the dom) app.controller() directive’s link functions (again if found) Here’s a simple demo where you can watch each execute (and experiment if you’d like). From Angular’s module docs: Run blocks – get executed after the injector is created and are used…

reduce function for array in javascript

Parameters callback Function to execute on each value in the array, taking four arguments: previousValue The value previously returned in the last invocation of the callback, or initialValue, if supplied. (See below.) currentValue The current element being processed in the array. index The index of the current element being processed in the array. array The…

prototype vs __proto__ in js

short version __proto__ is the actual object that is used in the lookup chain to resolve methods, etc. prototypeis the object that is used to build __proto__ when you create an object with new   long version prototype is a property of a Function object. It is the prototype of objects constructed by that function….

delete in js

The delete operator removes a property from an object. delete is only effective on an object’s properties. It has no effect on variable or function names. If the object inherits a property from a prototype, and doesn’t have the property itself, the property can’t be deleted by referencing the object. You can, however, delete it…

javascript IE memory leak

An unfortunate side effect of closures is that they make it trivially easy to leak memory in Internet Explorer. JavaScript is a garbage collected language — objects are allocated memory upon their creation and that memory is reclaimed by the browser when no references to an object remain. Objects provided by the host environment are…

javascript array in depth

What is an Array in JavaScript? A numerically indexed map of values. Traditionally an array reserves a continuous allocation of memory of predefined length. In JavaScript this is not the case. A JavaScript array is simply a glorified object with a unique constructor and literal syntax and an additional set of properties and methods inherited…

Comprehension Angular expression

Using ng-options was bit tough for me. I banged my head couple of times when I actually used ng-options in my code. And most of the times, I had to google and find out how to make it work. Looking the AngularJS documentation didn’t help much, as it’s less informative and doesn’t have much code…

$q and $promise in angularjs

$q and $promise The traditional way to deal with asynchronous tasks in Javascript are callbacks; call a method, give it a function reference to execute once that method is done. 1 2 3 $.get(‘api/gizmo/42’, function(gizmo) {   console.log(gizmo); // or whatever }); This is pretty neat, but, it has some drawbacks; for one, combining or chaining…