Easy learning with example program codes

Create JavaScript object

By Object() constructor:

var obj = new Object();

By Object.create() method:
Object.create: Will returns a new object with properties of prototypeObject.

var obj = Object.create(prototypeObject);

By bracket’s:
It is same as Object.create() method with null parameter.

var obj = {};

By function constructor:

var MySite = function(website) { = website;
var obj = new MySite("");

By function constructor with prototype:

function MySite(){}; = "";
var obj = new MySite();

By ES6 class syntax:

class MySite {
  constructor(name) { = name;
var obj = new MySite("");

By Singleton pattern:

var obj = new function(){ = "";

Related topics:

Please follow and like us:

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki