No announcement yet.

ECMAScript Objects

  • Filter
  • Time
  • Show
Clear All
new posts

  • ECMAScript Objects

    Object Oriented Programming! The way objects are created in ECMAScript is not exactly the way it is created in a language like PHP or C++. If you have learned the way objects are created in C++ or PHP, know that you would not just move into ECMAScript objects like that (conveniently). You have to learn the way objects are created ECMAScript. There is some good news though: it is easier to learn how to create and use objects in ECMAScript, than in C++ or PHP, if it is properly taught. In this article I introduce you to a tutorial series on ECMAScript Objects. There, ECMAScript Objects is properly taught.

    Class Approach and Prototyping Approach in OOP
    OOP stands for Object Oriented Programming. In OOP, the word, Class, means a set of variables and functions that would work together. In OOP, and in simple terms, the word, Object, is the class, where the variables have been assigned values and the class is actually usable. Object Oriented Programming is programming, whereby, instead of using variables and functions separately, variables and functions are grouped and used as groups.

    The word, Class, in OOP is similar to the dictionary meaning. In my dictionary, the word, Prototype, means, the first model or design of something from which other forms are copied or developed. In ECMAScript OOP, you do not have the Class; you have but the prototype. So far as houses are concerned, a class is like the blueprint, which builders read to build many houses; the houses are the objects. In the same thinking, the prototype is actually a house (a first house built); builders can look at the house, copy and build other houses that are the same or with modification (development).

    There are three ways of creating ECMAScript objects:

    You can create an object from a literal notation. In this case, you will type something like:

    myObject = {object variables and functions};

    Here, myObject is the variable that identifies the object. The object variables and functions are defined in the {} brackets. The {} brackets and content form the literal. The statement ends with a semicolon.

    Another way of creating an ECMAScript object is from a constructor function; something like,

    function theObject()
    object variables and functions

    In this code snippet, theObject is the name of the object.

    Another way of creating an ECMAScript object is by inheritance from the built-in ECMAScript object. ECMAScript has an object from which all other objects are inherited, indirectly. You will never see this object as you are coding. Even the objects from literal notation or constructor function are inherited from this object (indirectly). If you want to create an object by inheritance, you would have something like,

    myObject = new Object();
    //then you add the object variables and methods.

    Here, new is an ECMAScript operator; Object, which is case sensitive, refers to the built-in object, which has to be followed by ().

    You might have heard of JSON File. This is not another way of creating the ECMAScript object. It is a convenient way of browser Ajax, to download data as an object, from the server. You will see the details of this and the above three ways in the tutorial series.

    The tutorial series has been prepared in a step-by-step fashion. The code samples are well formatted with proper indentation, and so very readable. There is no missing special character, as you would find in web pages of other sites. The links to the different parts of the tutorial series are easily accessible from each page. To start the tutorials, click:

    Tutorials for ECMAScript Objects