{"id":42121,"date":"2021-08-23T03:33:14","date_gmt":"2021-08-23T03:33:14","guid":{"rendered":"https:\/\/www.oracletutoring.ca\/blog\/?p=42121"},"modified":"2021-08-23T03:33:16","modified_gmt":"2021-08-23T03:33:16","slug":"javascript-object-and-prototype-part0-1","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/javascript-object-and-prototype-part0-1\/","title":{"rendered":"JavaScript: object and prototype, part0.1"},"content":{"rendered":"\n<h2>Self-tutoring about JavaScript: the tutor continues about objects and the prototype connection.<\/h2>\n<p>It&#8217;s my understanding that in &#8220;old&#8221; JavaScript, you could have objects but they were defined using a constructor function, such as<\/p>\n<p>\nfunction theObj(the_name){<br\/><br\/>\nthis.name=the_name;<br\/>\n}<br\/>\n<br\/>\nvar myObj=new theObj(&#8216;Smedley&#8217;);\n<\/p>\n<p>The object above has no methods yet, but we could define one on its prototype (see my post <a href=\"https:\/\/www.oracletutoring.ca\/blog\/javascript-prototype\/\">here<\/a>), as follows:\n<\/p>\n<p>\ntheObj.prototype.tellAboutMe=function(){<br\/>\n<br\/>\nconsole.log(&#8220;My name is &#8220;+this.name+&#8221;.&#8221;);<br\/>\n};<br\/>\n<\/p>\n<p>\nNow, we can invoke the tellAboutMe method on myObj:<\/p>\n<p>myObj.tellAboutMe();<\/p>\n<p>Then we should receive the output <em>My name is Smedley<\/em>.\n<\/p>\n<p>The word class didn&#8217;t reach JavaScript until 2015. However, the new keyword was always part of it. That&#8217;s how I understand it, anyhow.<\/p>\n<p>Source:<\/p>\n<p><a href=\"https:\/\/www.w3schools.com\/js\/js_object_prototypes.asp\">w3schools.com<\/a><\/p>\n<p><a href=\"https:\/\/www.w3schools.com\/js\/js_classes.asp\">w3schools.com<\/a><\/p>\nJack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.\n\n\n","protected":false},"excerpt":{"rendered":"<p>Self-tutoring about JavaScript: the tutor continues about objects and the prototype connection. It&#8217;s my understanding that in &#8220;old&#8221; JavaScript, you could have objects but they were defined using a constructor function, such as function theObj(the_name){ this.name=the_name; } var myObj=new theObj(&#8216;Smedley&#8217;); &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/javascript-object-and-prototype-part0-1\/\"> <span class=\"screen-reader-text\">JavaScript: object and prototype, part0.1<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1745],"tags":[],"class_list":["post-42121","post","type-post","status-publish","format-standard","hentry","category-javascript-computer-science"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/42121","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=42121"}],"version-history":[{"count":6,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/42121\/revisions"}],"predecessor-version":[{"id":42127,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/42121\/revisions\/42127"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=42121"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=42121"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=42121"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}