Here is the code to rewrite our literal object using the new keyword:
var product = new Object();
product.name = "Chai";
product.category= "Tea";
product.country= "India";
product.supplier= {
name: "ACME Tea Of India",
location: "New Delhi"
};
product.related = new Array("Earl Grey", "Green Tea", "Dark Tea", "White Tea");
product.display = function () {
console.log(this);
};
Notice the object is the same as the object we created using the literal syntax but with the new keyword. Also we've created a custom object with the line
var product = new Object();
But we've also created a native object with the line:
product.related = new Array("Earl Grey", "Green Tea", "Dark Tea", "White Tea");
So the new keyword can be used to create both a custom object and a native object.
karabük
ReplyDeletesiirt
niğde
düzce
karaman
E5TKW