Giter VIP home page Giter VIP logo

js-object-creation-pattern's Introduction

js-object-creation-pattern

Javascript object creation patterns with examples (es6 and beyond)

NOTE: the tags (e.g (p1), (p.a)) within the parenthesis; they are guides also used in the code comment section to help one follow along

This are essential ways in which objects can be created in Javascript.

Essentially we'll cover 4 patterns which are

  1. Factory functions (p1)

  2. Constructors (p2)

  3. Prototype (p3)

  4. Dynamic prototype (p4)

  5. Factory function pattern essentially uses a function(s1) to return an object.

It entails 3 basic steps a. Initialize an EMPTY object (s2) b. assign properties and methods to the object within the function(s3) c. return the object (s4)

  1. The constructor pattern. you create object by initiating a constructor and invoking new object using the new keyword

steps a. create a constructor(s1) b. Invoke a new object from the constructor(s2)

  1. Prototype pattern essentially creates an object by assigning prototype to an empty function

It entails 2 basic steps a. Create an empty function b. assign the properties and method via prototype

The properties and method now created are passed from the parent to all newly created object via prototype

  1. The dynamic prototype pattern essentially aims to create light weight object by creating method within the prototype object dynamically. Its very similarly to the constructor pattern

steps

  1. create your constructor (s1)
  2. instantiate your property (s2)
  3. Set a conditional that checks and create method within the prototype property (s3)

js-object-creation-pattern's People

Contributors

ayoola-moore avatar hayola avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.