Tag | javascript

  1. JavaScript Object.defineProperty()

    In Javascript, we can add a property to an object with:

    obj.property = value;

    However, sometimes we would like to have fine-grained control over properties. With Object.defineProperty(), we can decide:

    Descriptor Purpose Default
    value Property value undefined
    writable Whether the property can be assigned false
    get Getter of the …


  2. NPM Package Manager

    NPM package manager plays an important role in Node.js ecosystem. Every serious Javascript developers should learn how to create a package with npm. In this post, I am going to cover several important npm commands.

    Initialize a NPM Package

    To start a project, we have to create package.json …


  3. A Quick Guide to Grunt

    Grunt is a task runner for Javascript development. Grunt automates the process to bundle, transpile, uglify, and compress the Javascript source code. This post would like to give a quick guide to Grunt.


    Our first step is to create a package.json. We will need a package.json to …


  4. JavaScript Prototype and Object Oriented

    Javascript is a prototype-based object-oriented programming language. Unlike the conventional class-based object-oriented programming languages (e.g. C++ or Java), which ask programmers to write a class and then instantiate several similar objects from the class, Javascript adopts a different approach. In the world of Javascript, we have to craft a …


  5. Read Lines from stdin in Node.js

    It is easy to write a hello world program in Node.js:

    console.log("Hello world!")

    However, due to the asynchronous nature of Javascript, reading inputs and writing outputs are less straight-forward. We have to pass the callback functions or register event listeners.

    First Attempt

    For example, to read some …


  6. Browserify

    It is common to organize the code in several modules when we are developing Javascript applications. In Node.js ecosystem, we can import a module with the require() function and export symbols by adding them to the module.exports object. On the other hand, ES2015 adds import statements and export …