ECMAScript 6 introduced the let statement. The difference is scoping. var is scoped to the nearest function block and let is scoped to the nearest enclosing block, which can be smaller than a function block. Both are global if outside any block. Also, variables declared with let are not accessible before they are declared in … Continue reading What’s the difference between using “let” and “var” to declare a variable in JavaScript?
JavaScript
an OCR Engine in JavaScript
Tesseract.js is a javascript library that gets words in almost any language out of images. Below is an example tested with Node.js (local file system). Note that your will need to download the trained language data for the language here. Unzip the file and put it somewhere in your solution. Then the call to Tesseract … Continue reading an OCR Engine in JavaScript
What is the lifecycle of an AngularJS Controller?
Can someone please clarify what the lifecycle of an AngularJS controller is? Is a controller a singleton, or created / destroyed on demand? If the latter, what triggers the creation / destruction of the controller? Consider the below example: var demoApp = angular.module('demo') .config(function($routeProvider, $locationProvider) { $routeProvider .when('/home', {templateUrl: '/home.html', controller: 'HomeCtrl'}) .when('/users',{templateUrl: '/users.html', controller: … Continue reading What is the lifecycle of an AngularJS Controller?
Posting Form Data With $http In AngularJS
By default, when you go to post data in an AngularJS application, the data is serialized using JSON (JavaScript Object Notation) and posted to the server with the content-type, "application/json". But, if you want to post the data as a regular "form post," you can; all you have to do is override the default request … Continue reading Posting Form Data With $http In AngularJS
Angular $http POST request with request payload or form data
If you have RESTful API's on your server side and are trying to use Angular's $http service to consume the resource, you should be careful about how the request (for example, Http POST) is made, in particular how the data (perhaps in the format of form) is included in the request. As a JSON object … Continue reading Angular $http POST request with request payload or form data
HTTP request in Node.js or other JavaScript framework
You should always consider using the Object provided by the MV* framework. If the JS framework doesn't have a built-in support for communicating with the server (which I highly doubt), you can opt to work directly with the low-level methods of the XMLHttpRequest object itself or use a general utility library such as JQuery. On … Continue reading HTTP request in Node.js or other JavaScript framework
Module in JavaScript
A short personal note: var dayName = function() {}(); is equivalent to var dayName = function() {}; dayName(); You define a function first then invoke it. Modules A beginning programmer writes her programs like an ant builds her hill, one piece at a time, without thought for the bigger structure. Her programs will be like … Continue reading Module in JavaScript
Fixing the Back Button: A Simple SPA Behavior using Location Hash
Introduction Using a SPA framework, like AngularJS, is overkill for a simple one-page website. But, suppose that single web page has pseudo-navigation needs, like a dialog that opens in response to the user clicking a button. This represents a state transition, and clicking the back button in the browser (or on an Android or Windows Phone) … Continue reading Fixing the Back Button: A Simple SPA Behavior using Location Hash
JavaScript Object Prototypes (prototype property in JS)
Every JavaScript object has a prototype. The prototype is also an object. All JavaScript objects inherit their properties and methods from their prototype. JavaScript Prototypes All JavaScript objects inherit the properties and methods from their prototype. Objects created using an object literal, or with new Object(), inherit from a prototype called Object.prototype. Objects created with … Continue reading JavaScript Object Prototypes (prototype property in JS)
An IDE for web development (i.e., HTML, CSS, and JS)
Some people recommend Aptana Studio. Not sure if it's useful. Isn't a Gedit or Geany sufficiently good? A quick note on installing Aptana Studio on Windows. You need to have 32-bit Java installed prior to. Otherwise you see "returned exit code=13" error. After you install 32-bit Java into C:program files(x86)/java/ Go to apatana folder and … Continue reading An IDE for web development (i.e., HTML, CSS, and JS)