{"id":37907,"date":"2017-09-04T23:01:41","date_gmt":"2017-09-04T15:01:41","guid":{"rendered":"https:\/\/www.hongkiat.com\/blog\/?p=37907"},"modified":"2023-04-06T19:06:50","modified_gmt":"2023-04-06T11:06:50","slug":"object-oriented-javascript","status":"publish","type":"post","link":"https:\/\/www.hongkiat.com\/blog\/object-oriented-javascript\/","title":{"rendered":"3 Ways to Create Object Instances in OOJS"},"content":{"rendered":"<p>When a programming language is <strong>all about objects<\/strong>, the first thing we need to learn is <strong>how to create objects<\/strong>. Creating objects in JavaScript is fairly easy: <strong>a pair of curly braces<\/strong> will do the job, however, that is <strong>neither the only way<\/strong> to create an object <strong>nor the only way<\/strong> you\u2019ll ever need to use.<\/p>\n<p>In JavaScript, object instances are <strong>created from <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en\/docs\/Web\/JavaScript\/Reference\/Global_Objects\">built-in objects<\/a><\/strong> and come to existence when the program is running. For example, <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Date\"><code>Date<\/code><\/a> is a built-in object that gives us information about dates. If we want to show the current date on a page, we <strong>need a runtime instance of <code>Date<\/code><\/strong> that carries the information about the current date.<\/p>\n<p>JavaScript also allows us to <strong>define our own objects<\/strong> that can produce their own object instances in runtime. In JavaScript, <strong>everything is an object<\/strong> and every object has an <strong>ultimate ancestor<\/strong> called <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Object\"><code>Object<\/code><\/a>. The creation of  an object instance is called <strong>instantiation<\/strong>.<\/p>\n<p class=\"note\"><strong>Read Also:<\/strong> <a href=\"https:\/\/www.hongkiat.com\/blog\/getters-setters-javascript\/\">Ultimate Guide to Getters and Setters in JavaScript<\/a><\/p>\n<h2>1. The <code>new<\/code> operator<\/h2>\n<p>One of the most common and well-known methods to create a new object instance is by <strong>using the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Operators\/new\"><code>new<\/code><\/a> operator<\/strong>.<\/p>\n<p>You need a <strong>constructor<\/strong> to make the <code>new<\/code> operator work. A constructor is a method of an object that puts together a <strong>new instance of that object<\/strong>. Its basic syntax looks like this:<\/p>\n<pre>\r\nnew constructor()\r\n<\/pre>\n<p>A constructor can <strong>accept arguments<\/strong> that can be used to change or add properties to the object instance it constructs. The constructor <strong>has the same name<\/strong> as the object it belongs to.<\/p>\n<p>Here is an example how to create an <strong>instance of the <code>Date()<\/code> object<\/strong> with the <code>new<\/code> keyword:<\/p>\n<pre>\r\ndt = new Date(2017, 0 , 1)\r\nconsole.log(dt)\r\n\/\/ Sun Jan 01 2017 00:00:00 GMT+0100\r\n<\/pre>\n<p><code>Date()<\/code> is the constructor to create a new <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Date\"><code>Date<\/code><\/a> object. Different constructors for an object <strong>take different arguments<\/strong> to create the same kind of object instances with <strong>varied attributes<\/strong>.<\/p>\n<p>Not all built-in objects in JavaScript\t can be instantiated like <code>Date<\/code>. There are objects that <strong>don\u2019t come with a constructor<\/strong>: <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Math\"><code>Math<\/code><\/a>, <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/JSON\"><code>JSON<\/code><\/a> and <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Reflect\"><code>Reflect<\/code><\/a>, but they\u2019re still ordinary objects.<\/p>\n<p>Among the built-in objects that have constructor(s), <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Symbol\"><code>Symbol<\/code><\/a> <strong>cannot be called in the constructor style<\/strong> to instantiate a new <code>Symbol<\/code> instance. It can only be <strong>called as a function<\/strong> which returns a new <code>Symbol<\/code> value.<\/p>\n<p>Also, among the built-in objects that have constructor(s), not all need their constructors to be called with the <code>new<\/code> operator in order to be instantiated. <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Function\"><code>Function<\/code><\/a>, <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Array\"><code>Array<\/code><\/a>, <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Error\"><code>Error<\/code><\/a>, and <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/RegExp\"><code>RegExp<\/code><\/a> <strong>can also be called as functions<\/strong>, without using the <code>new<\/code> keyword, and they\u2019ll instantiate and return a new object instance.<\/p>\n<h2>2. The <code>Reflect<\/code> object<\/h2>\n<p>Backend programmers might be already familiar with <strong>Reflection APIs<\/strong>. Reflection is a feature of programming languages to <strong>inspect and update some of the basic entities<\/strong>, such as objects and classes, <strong>at runtime<\/strong>.<\/p>\n<p>In JavaScript, you could already perform <em>some<\/em> reflection operations using <code>Object<\/code>. But, a <strong>proper Reflection API<\/strong> eventually came to exist in JavaScript as well.<\/p>\n<p>The <strong><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Reflect\"><code>Reflect<\/code><\/a><\/strong> object has a set of methods to <strong>create and update object instances<\/strong>. The <code>Reflect<\/code> object <strong>doesn\u2019t have a constructor<\/strong>, so it can\u2019t be instantiated with the <code>new<\/code> operator, and, just like <code>Math<\/code> and <code>JSON<\/code>, it <strong>can\u2019t be called as a function<\/strong> either.<\/p>\n<p>However, <code>Reflect<\/code> has an <strong>equivalent of the <code>new<\/code> operator<\/strong>: the <strong><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Reflect\/construct\"><code>Reflect.construct()<\/code><\/a><\/strong> method.<\/p>\n<pre>\r\nReflect.construct(target, argumentsList[, newTarget])\r\n<\/pre>\n<p>Both the <code>target<\/code> and the optional <code>newTarget<\/code> arguments are <strong>objects having their own  constructors<\/strong>, while <code>argumentsList<\/code> is a <strong>list of arguments<\/strong> to be passed to the constructor of <code>target<\/code>.<\/p>\n<pre>\r\nvar dt = Reflect.construct(Date, [2017, 0 , 1]);\r\nconsole.log(dt);\r\n\/\/ Sun Jan 01 2017 00:00:00 GMT+0100\r\n<\/pre>\n<p>The code above <strong>has the same effect<\/strong> as instantiating <code>Date()<\/code> using the <code>new<\/code> operator. Although you can still use <code>new<\/code>, Reflection is an <strong>ECMAScript 6 standard<\/strong>. It also allows you to <strong>make use of the <code>newTarget<\/code> argument<\/strong>, which is another advantage over the <code>new<\/code> operator.<\/p>\n<p class=\"note\"><strong>Read Also:<\/strong> <a href=\"https:\/\/www.hongkiat.com\/blog\/ecmascript-6\/\">ECMAScript 6 \u2013 10 Awesome New Features<\/a><\/p>\n<p>The value of <code>newTarget<\/code>\u2018s prototype (to be exact, it\u2019s the prototype of <code>newTarget<\/code>\u2018s constructor) <strong>becomes the prototype of the newly created instance<\/strong>.<\/p>\n<p>A <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Object\/prototype\">prototype<\/a> is the <strong>property of an Object<\/strong>, the value of which is <strong>also an object<\/strong>, carrying the properties of the original object. In short, an object gets its members from its prototype.<\/p>\n<p>Here, let\u2019s see an example:<\/p>\n<pre>\r\nclass A {\r\n  constructor() {\r\n    this.message = function() {\r\n      console.log('message from A')\r\n    }\r\n  }\r\n}\r\n\r\nclass B {\r\n  constructor() {\r\n  }\r\n  message() {\r\n    console.log('message from B')\r\n  }\r\n  data() {\r\n    console.log('data from B')\r\n  }\r\n}\r\n\r\nobj = Reflect.construct(A, [], B)\r\n\r\nconsole.log(obj.message());\r\n\/\/ message from A\r\n\r\nconsole.log(obj.data());\r\n\/\/ data from B\r\n\r\nconsole.log(obj instanceof B)\r\n\/\/ true\r\n<\/pre>\n<p>By passing <code>B<\/code> as the third argument to <code>Reflect.construct()<\/code>, the prototype value of the <code>obj<\/code> object is <strong>made to be same<\/strong> as the prototype of <code>B<\/code>\u2018s constructor (which has the properties <code>message<\/code> and <code>data<\/code>).<\/p>\n<p>Thus, <code>obj<\/code> <strong>can access the <code>message<\/code> and <code>data<\/code><\/strong>, available at its prototype. But, since <code>obj<\/code> is made using <code>A<\/code>, it also has its own <code>message<\/code> it <strong>received from <code>A<\/code><\/strong>.<\/p>\n<p>Even though <code>obj<\/code> is constructed as an array, it is <strong>not an instance of <code>Array<\/code><\/strong>, because its prototype is set to <code>Object<\/code>.<\/p>\n<pre>\r\nobj = Reflect.construct(Array, [1,2,3], Object)\r\n\r\nconsole.log(obj)\r\n\/\/ Array [ 1, 2, 3 ]\r\n\r\nconsole.log(obj instanceof Array)\r\n\/\/ false\r\n<\/pre>\n<p><code>Reflect.construct()<\/code> can be useful when you want to create an object <strong>using more than one blueprint<\/strong>.<\/p>\n<h2>3. The <code>Object.create()<\/code> method<\/h2>\n<p>You can also create a <strong>new ordinary object with a specific prototype<\/strong> via <strong><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/developer.mozilla.org\/en\/docs\/Web\/JavaScript\/Reference\/Global_Objects\/Object\/create\"><code>Object.create()<\/code><\/a><\/strong>. This, too, might seem very similar to using the <code>new<\/code> operator, but it\u2019s not.<\/p>\n<pre>\r\nObject.create(O[, propertiesObject])\r\n<\/pre>\n<p>The <code>O<\/code> argument is an object that <strong>serves the prototype<\/strong> for the new object that will be created. The optional <code>propertiesObject<\/code> argument is a <strong>list of properties<\/strong> you might want to add to the new object.<\/p>\n<pre>\r\nclass A {\r\n  constructor() {\r\n  }\r\n  message() {\r\n    console.log('message from A')\r\n  }\r\n}\r\n\r\nvar obj = Object.create(new A(), {\r\n  data: {\r\n    writable: true,\r\n    configurable: true,\r\n    value: function(){return 'data from obj'}\r\n  }\r\n})\r\n\r\nconsole.log(obj.message())\r\n\/\/ message from A\r\n\r\nconsole.log(obj.data())\r\n\/\/ data from obj\r\n\r\nobj1 = Object.create(new A(), {\r\n  foo: {\r\n    writable: true,\r\n    configurable: true,\r\n    value: function(){return 'foo from obj1'}\r\n  }\r\n})\r\n\r\nconsole.log(obj1.message())\r\n\/\/ message from A\r\n\r\nconsole.log(obj1.foo())\r\n\/\/ foo from obj1\r\n<\/pre>\n<p>In the <code>obj<\/code> object, the added property is <code>data<\/code>, while in <code>obj1<\/code>, it\u2019s <code>foo<\/code>. So, as you see, we can have <strong>properties and methods added to a new object<\/strong>.<\/p>\n<p>This is great when you want to create <strong>multiple objects of the same kind<\/strong> but with <strong>different supplementary properties or methods<\/strong>. The <code>Object.create()<\/code> syntax saves the trouble of coding all of them separately.<\/p>\n<p class=\"note\"><strong>Read Also:<\/strong> <a href=\"https:\/\/www.hongkiat.com\/blog\/javascript-promise-object\/\">Getting Started with JavaScript Promises<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>When a programming language is all about objects, the first thing we need to learn is how to create objects. Creating objects in JavaScript is fairly easy: a pair of curly braces will do the job, however, that is neither the only way to create an object nor the only way you\u2019ll ever need to&hellip;<\/p>\n","protected":false},"author":145,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3392],"tags":[4117],"topic":[4520],"class_list":["entry-content","is-maxi"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v22.8 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>3 Ways to Create Object Instances in OOJS - Hongkiat<\/title>\n<meta name=\"description\" content=\"When a programming language is all about objects, the first thing we need to learn is how to create objects. Creating objects in JavaScript is fairly\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hongkiat.com\/blog\/object-oriented-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"3 Ways to Create Object Instances in OOJS\" \/>\n<meta property=\"og:description\" content=\"When a programming language is all about objects, the first thing we need to learn is how to create objects. Creating objects in JavaScript is fairly\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hongkiat.com\/blog\/object-oriented-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"Hongkiat\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hongkiatcom\" \/>\n<meta property=\"article:published_time\" content=\"2017-09-04T15:01:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-04-06T11:06:50+00:00\" \/>\n<meta name=\"author\" content=\"Preethi Ranjit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:site\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Preethi Ranjit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/object-oriented-javascript\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/object-oriented-javascript\\\/\"},\"author\":{\"name\":\"Preethi Ranjit\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e981676afae36d1ff5feb75094950ab3\"},\"headline\":\"3 Ways to Create Object Instances in OOJS\",\"datePublished\":\"2017-09-04T15:01:41+00:00\",\"dateModified\":\"2023-04-06T11:06:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/object-oriented-javascript\\\/\"},\"wordCount\":846,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"keywords\":[\"Javascripts\"],\"articleSection\":[\"Coding\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/object-oriented-javascript\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/object-oriented-javascript\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/object-oriented-javascript\\\/\",\"name\":\"3 Ways to Create Object Instances in OOJS - Hongkiat\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\"},\"datePublished\":\"2017-09-04T15:01:41+00:00\",\"dateModified\":\"2023-04-06T11:06:50+00:00\",\"description\":\"When a programming language is all about objects, the first thing we need to learn is how to create objects. Creating objects in JavaScript is fairly\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/object-oriented-javascript\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/object-oriented-javascript\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/object-oriented-javascript\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"3 Ways to Create Object Instances in OOJS\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"name\":\"Hongkiat\",\"description\":\"Tech and Design Tips\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\",\"name\":\"Hongkiat.com\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"contentUrl\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"width\":1200,\"height\":799,\"caption\":\"Hongkiat.com\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/hongkiatcom\",\"https:\\\/\\\/x.com\\\/hongkiat\",\"https:\\\/\\\/www.pinterest.com\\\/hongkiat\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e981676afae36d1ff5feb75094950ab3\",\"name\":\"Preethi Ranjit\",\"description\":\"A .NET developer with a JavaScript background, Preethi is expert in front-end coding, JavaScript, HTML, and CSS.\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/author\\\/preethi\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"3 Ways to Create Object Instances in OOJS - Hongkiat","description":"When a programming language is all about objects, the first thing we need to learn is how to create objects. Creating objects in JavaScript is fairly","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.hongkiat.com\/blog\/object-oriented-javascript\/","og_locale":"en_US","og_type":"article","og_title":"3 Ways to Create Object Instances in OOJS","og_description":"When a programming language is all about objects, the first thing we need to learn is how to create objects. Creating objects in JavaScript is fairly","og_url":"https:\/\/www.hongkiat.com\/blog\/object-oriented-javascript\/","og_site_name":"Hongkiat","article_publisher":"https:\/\/www.facebook.com\/hongkiatcom","article_published_time":"2017-09-04T15:01:41+00:00","article_modified_time":"2023-04-06T11:06:50+00:00","author":"Preethi Ranjit","twitter_card":"summary_large_image","twitter_creator":"@hongkiat","twitter_site":"@hongkiat","twitter_misc":{"Written by":"Preethi Ranjit","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hongkiat.com\/blog\/object-oriented-javascript\/#article","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/object-oriented-javascript\/"},"author":{"name":"Preethi Ranjit","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e981676afae36d1ff5feb75094950ab3"},"headline":"3 Ways to Create Object Instances in OOJS","datePublished":"2017-09-04T15:01:41+00:00","dateModified":"2023-04-06T11:06:50+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/object-oriented-javascript\/"},"wordCount":846,"commentCount":0,"publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"keywords":["Javascripts"],"articleSection":["Coding"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.hongkiat.com\/blog\/object-oriented-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.hongkiat.com\/blog\/object-oriented-javascript\/","url":"https:\/\/www.hongkiat.com\/blog\/object-oriented-javascript\/","name":"3 Ways to Create Object Instances in OOJS - Hongkiat","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/#website"},"datePublished":"2017-09-04T15:01:41+00:00","dateModified":"2023-04-06T11:06:50+00:00","description":"When a programming language is all about objects, the first thing we need to learn is how to create objects. Creating objects in JavaScript is fairly","breadcrumb":{"@id":"https:\/\/www.hongkiat.com\/blog\/object-oriented-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hongkiat.com\/blog\/object-oriented-javascript\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.hongkiat.com\/blog\/object-oriented-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hongkiat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"3 Ways to Create Object Instances in OOJS"}]},{"@type":"WebSite","@id":"https:\/\/www.hongkiat.com\/blog\/#website","url":"https:\/\/www.hongkiat.com\/blog\/","name":"Hongkiat","description":"Tech and Design Tips","publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hongkiat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.hongkiat.com\/blog\/#organization","name":"Hongkiat.com","url":"https:\/\/www.hongkiat.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","contentUrl":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","width":1200,"height":799,"caption":"Hongkiat.com"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/hongkiatcom","https:\/\/x.com\/hongkiat","https:\/\/www.pinterest.com\/hongkiat\/"]},{"@type":"Person","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e981676afae36d1ff5feb75094950ab3","name":"Preethi Ranjit","description":"A .NET developer with a JavaScript background, Preethi is expert in front-end coding, JavaScript, HTML, and CSS.","url":"https:\/\/www.hongkiat.com\/blog\/author\/preethi\/"}]}},"jetpack_featured_media_url":"https:\/\/","jetpack_shortlink":"https:\/\/wp.me\/p4uxU-9Rp","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/37907","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/users\/145"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/comments?post=37907"}],"version-history":[{"count":2,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/37907\/revisions"}],"predecessor-version":[{"id":65679,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/37907\/revisions\/65679"}],"wp:attachment":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/media?parent=37907"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/categories?post=37907"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/tags?post=37907"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/topic?post=37907"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}