Jun 13, 2016

Javascript Prototypes For Performance

Without Prototype : Lots of memory per object
  • Each time when you create object from below vehicle function,
  • the line function(name){  this.name = name;  }  is alocated memory each time the object is created,
  • so there are multiple instances of same function.
function vehicle(){
    this.name = 'truck';
    this.set_name = function(name){ 
        this.name = name; 
    }
}
var taxi = new vehicle();

Mar 23, 2016

Ways to export modules in nodejs

there are several ways to export modules in nodejs

  1. Simplest export
  2. Define a global
  3. Export by anonymous function
  4. Export by named function
  5. Export by anonymous object
  6. Export by named object
  7. Export by anonymous prototype
  8. Export by named prototype
  9. Export by Json

1. Simplest export

//hello.js
console.log('Hello World');

// app.js
require('hello.js');