{"id":55039,"date":"2022-03-03T03:01:39","date_gmt":"2022-03-02T17:01:39","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=55039"},"modified":"2022-03-03T13:49:44","modified_gmt":"2022-03-03T03:49:44","slug":"javascript-object-oriented-programming-constructor-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/javascript-object-oriented-programming-constructor-primer-tutorial\/","title":{"rendered":"Javascript Object Oriented Programming Constructor Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/since_1970.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Javascript Object Oriented Programming Constructor Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/since_1970.jpg\" title=\"Javascript Object Oriented Programming Constructor Primer Tutorial\"  style=\"float:left;\" \/><\/a><p class=\"wp-caption-text\">Javascript Object Oriented Programming Constructor Primer Tutorial<\/p><\/div>\n<p>An important aspect to any <a target=_blank title='OOP information from Wikipedia, thanks' href='https:\/\/en.wikipedia.org\/wiki\/Object-oriented_programming'>Object Oriented Programming<\/a> (or OOP) discussion would have to include an early introduction to the concept of the (object) <a target=_blank title='OOP Constructor information from Wikipedia, thanks' href='https:\/\/en.wikipedia.org\/wiki\/Constructor_(object-oriented_programming)'>Constructor<\/a> &#8230;<\/p>\n<blockquote cite='https:\/\/en.wikipedia.org\/wiki\/Constructor_(object-oriented_programming)'><p>\nIn class-based object-oriented programming, a constructor is a special type of subroutine called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables.\n<\/p><\/blockquote>\n<p>The nature of method signatures including &#8230;<\/p>\n<ul>\n<li>method name &#8230; and &#8230;<\/li>\n<li>arguments (also known as parameters) &#8230; and &#8230;<\/li>\n<li>return value(s)<\/li>\n<\/ul>\n<p> &#8230; &#8220;tests&#8221; for uniqueness, and so, validity, means that any one <a target=_blank title='OOP class information from Wikipedia, thanks' href='https:\/\/en.wikipedia.org\/wiki\/Class_(computer_programming)'>&#8220;class&#8221;<\/a> (like a &#8220;blueprint&#8221;, where &#8220;Constructors&#8221; are defined for the deployed &#8220;objects&#8221; to follow) can have multiple (method name) &#8220;Constructors&#8221; defined.<\/p>\n<p>So, how best to illustrate this?  Well, with Javascript <font size=1>(where, as with other languages that support OOP, you can mix OOP style programming with non-OOP style programming, should you wish)<\/font>, we often use the <a target=_blank title='Javascript Date object information from W3schools' href='https:\/\/www.w3schools.com\/js\/js_dates.asp'>Date<\/a> object when we have a web application involving the &#8220;when&#8221; of life.   Look at the four ways below you can &#8220;construct&#8221; a Date object &#8230;<\/p>\n<blockquote cite='https:\/\/www.w3schools.com\/js\/js_dates.asp'><p>\nCreating Date Objects<br \/>\nDate objects are created with the new Date() constructor.<br \/>\n<br \/>\nThere are 4 ways to create a new date object:<br \/>\n<br \/>\nnew Date()<br \/>\nnew Date(year, month, day, hours, minutes, seconds, milliseconds)<br \/>\nnew Date(milliseconds)<br \/>\nnew Date(date string)\n<\/p><\/blockquote>\n<p>Interesting, huh?!  The first we use most commonly, resulting in a Date object describing the Date and Time it is when the codeline executes.  The second is used to recreate a Date and Time you have information about.   The fourth is a way to create a Date object via a timestamp string.<\/p>\n<p>We think the third one above is very intriguing and revealing!   Could it be that the computer view of a Date object&#8217;s data be as simple as containable in a single &#8220;counting number&#8221; (or integer) type of data item?  Yup!  It&#8217;s been organized that way because it was decided that <i>1st January 1970 00:00:00<\/i> should be the starting point (ie. parameter zero) for this arrangement.  For a lot of us &#8220;oldies&#8221; then, the sad news is, to describe your birth day will need the second or fourth constructors, <a onclick=\"document.getElementById('spanboomer').style.display='inline-block';\" onmouseover=\"document.getElementById('spanboomer').style.display='inline-block';\" style=\"cursor:pointer;text-decoration:underline;\">only!<\/a> <span id=spanboomer style=display:none;color:red;>Hello Boomer Revenge clause is that constructor three parameter can be negative! Don&#8217;t like to be too childish here, but &#8230; ngarh, ngarh ngarh ngarh, ngarrrhhhh!<\/span>  But cheer up, because this arrangement is really great for computer speed processing Date object logic.<\/p>\n<p>We decided to write a bit of a &#8220;proof of concept&#8221; (fun and) game<font size=1>s<\/font> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/since_1970.html_GETME\">since_1970.html<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/since_1970.html\">web application Game<\/a> to give you a feel for all of this, that features &#8220;Constructors&#8221; two and three above.  You can also try it below &#8230;<\/p>\n<p><iframe src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/since_1970.html\" style=\"width:100%;height:700px;\"><\/iframe><\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d55039' onclick='var dv=document.getElementById(\"d55039\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/date\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d55039' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>An important aspect to any Object Oriented Programming (or OOP) discussion would have to include an early introduction to the concept of the (object) Constructor &#8230; In class-based object-oriented programming, a constructor is a special type of subroutine called to &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/javascript-object-oriented-programming-constructor-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,15,28,37],"tags":[3925,210,2078,3924,301,476,477,3922,576,2991,652,1830,3923,849,2010,875,997,1986,3401,1319],"class_list":["post-55039","post","type-post","status-publish","format-standard","hentry","category-elearning","category-games","category-oop","category-tutorials","tag-blueprint","tag-class","tag-constructor","tag-counting-number","tag-date","tag-game","tag-games-2","tag-guess","tag-html","tag-integer","tag-javascript","tag-method","tag-milliseconds","tag-object","tag-object-oriented-programming","tag-oop","tag-programming","tag-proof-of-concept","tag-seconds","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/55039"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=55039"}],"version-history":[{"count":19,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/55039\/revisions"}],"predecessor-version":[{"id":55078,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/55039\/revisions\/55078"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=55039"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=55039"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=55039"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}