Hi Folks, Object literal notation Object literal notation, which we also cover in the Module pattern section, can be thought of as an object containing a collection of key-value pairs with a colon separating each pair of keys and values, where keys can also represent new namespaces. eg: var appMyapp = {}; appMyapp.foo = function(){ return "bar"; } appMyapp.utills = fuction(){ toString:function(){ }, }
Posts
Showing posts from March, 2017
- Get link
- X
- Other Apps
Hi Folks, Prefix Namespacing in Javascript. One solution to the above problem, as mentioned by Peter Michaux , is to use prefix namespacing. It’s a simple concept at heart, but the idea is we select a unique prefix namespace we wish to use (in this example, myApplication_ ) and then define any methods, variables, or other objects after the prefix as follows: var myapplication_property1 = {}; var myapplication_property2 = {}; function myapplication_method(){ //..... }
- Get link
- X
- Other Apps
Hi Folks, Namespacing in Javascript Single Global Variable: One popular pattern for namespacing in JavaScript is opting for a single global variable as our primary object of reference. A skeleton implementation of this where we return an object with functions and properties can be found below: var myApp = (function () { function(){ //...... }, return{ //...... } })
- Get link
- X
- Other Apps
SERVER-SIDE PDF GENERATION AND ANGULAR $RESOURCE I ran into a problem recently where my Angular application needed to consume an API call that returned a PDF response. Apparently there are options to generate PDF documents client-side, such as Mozilla's PDF.js , but in this case I had no control over the data. The scenario looked like this: Send a HTTP request with an Accept header of application/pdf and expect to recieve a PDF byte-stream response. Allow the user to download this PDF from their browser after making the call. I had no access to the server in this scenario since my Angular application is stateless and relies primarily on ngResource to consume external API payloads. I simply wanted the user to click a "Download PDF" button and have the browser prompt them to download the file. I managed to accomplish this by adding a new method to the ngResource object: pdf: { method: 'GET' , headers: { accept: 'application/pdf...