{"id":56200,"date":"2022-06-22T03:01:32","date_gmt":"2022-06-21T17:01:32","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=56200"},"modified":"2022-06-22T07:13:35","modified_gmt":"2022-06-21T21:13:35","slug":"window-object-method-override-return-values-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/window-object-method-override-return-values-tutorial\/","title":{"rendered":"Window Object Method Override Return Values Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/window_object_method_override.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Window Object Method Override Return Values Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/window_object_method_override_oneobject.jpg\" title=\"Window Object Method Override Return Values Tutorial\"  style=\"float:left;\"   \/><\/a><p class=\"wp-caption-text\">Window Object Method Override Return Values Tutorial<\/p><\/div>\n<p>It is somewhat true that Javascript does not care about the <i>type of<\/i> var<font size=1>iable<\/font> your non-array variable is, in the sense that &#8230;<\/p>\n<ul>\n<li>strings &#8230; and &#8230;<\/li>\n<li>(any of the forms of) integers or real numbers<\/li>\n<\/ul>\n<p> &#8230; can be &#8220;housed&#8221; under a string guise, the latter always able to go back to the former via a Javascript codeline like the last one below &#8230;<\/p>\n<p><code><br \/>\n var ournumis = 89765.675;<br \/>\n var ourstris = '' + ournumis;<br \/>\n<\/code><\/p>\n<p>Javascript is &#8220;untyped&#8221; <font size=1>(by and large)<\/font>.  PHP is a <i>loosely typed language<\/i>.  C++ or C# or C are a huge break from this &#8220;looseness&#8221;, by comparison.<\/p>\n<p>Javascript can be fussy about an &#8220;object&#8221; though.  Pretty obviously, if Javascript code tries to access the method of an &#8220;object&#8221;, and does not succeed, then that is a problem.  Similarly for arrays, if an indexed reference to an array var<font size=1>iable<\/font> does not exist, then that is a problem too.<\/p>\n<p>Some of yesterday&#8217;s <a title='Window Object Method Override Textbox Tutorial' href='#womott'>Window Object Method Override Textbox Tutorial<\/a>&#8216;s Window Object Method calls involve an &#8220;object&#8221;, and here, today, with our changes, we remedy some of the weaknesses of yesterday&#8217;s treatment of all those first parameters, as if they could all be described as a string.<\/p>\n<\/p>\n<p>Javascript <a target=_blank href='http:\/\/www.w3schools.com\/jsref\/jsref_eval.asp' title='Javascript eval'>eval<\/a> comes to our aid, here &#8230; again.  Take a look at the Javascript codelines below &#8230;<\/p>\n<p><code><br \/>\n      one=eval(function(){ console.log( (new Date() ) ); });<br \/>\n      eval('one=function' + tih.split('(function')[1].split('}')[0] + '}');<br \/>\n      eval(\"one=\" + selo.options[selo.selectedIndex].innerHTML);<br \/>\n<\/code><\/p>\n<p> &#8230; that are all &#8220;object&#8221; assignments to (global Javascript) var<font size=1>iable<\/font> <i>one<\/i> that allow for dynamic situations to be catered for with these assignments.<\/p>\n<p>Readers new to Javascript may be taken aback that (global Javascript) var<font size=1>iable<\/font> <i>one<\/i> can be a string or number or object (and, who knows, into the future, perhaps, an array), but that&#8217;s Javascript, &#8220;it depends&#8221; or &#8220;it&#8217;s contextual&#8221;, but you do get used to it, and as for yours truly, get to really like its chaotic and unruly, but really flexible, nature.<\/p>\n<p>With all this in mind then, you won&#8217;t be surprised to find we add into our scope of work one new global Javascript var<font size=1>iable<\/font ...<\/p>\n<p><code><br \/>\n  var lasto=null;<br \/>\n<\/code><\/p>\n<p> &#8230; which we&#8217;ll use a lot more as a default <i>return value<\/i> for our Window Object Method (as overridden) calls, <font color=blue>such as<\/font> yesterday&#8217;s changed global Javascript var<font size=1>iable<\/font> <i>template<\/i> &#8230;<\/p>\n<p><code><br \/>\n  var template=\"const prompt = (one,two) => {     <font color=blue>lasto=<\/font>window.prompt(one,two);   };\";<br \/>\n<\/code><\/p>\n<p> &#8230; so that other subsequent Window Object Method (as overridden) calls might call on that <i>lasto<\/i> &#8220;object&#8221; (perhaps) var<font size=1>iable<\/font> to good cause, such as &#8230;<\/p>\n<p><code><br \/>\nconst open = (one,two,three) => { lasto=window.open(one,two,three); };<br \/>\n<\/code><\/p>\n<p> &#8230; preceding &#8230;<\/p>\n<p><code><br \/>\nconst close = () => { lasto.close(); };<br \/>\n<\/code><\/p>\n<p> &#8230; to open and close a webpage window, as a couple of examples of Windows Object Method (overwrite) examples in <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/window_object_method_override.html--GETME\" title=\"window_object_method_override.html\">the changed<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/window_object_method_override.html--GETME\" title=\"window_object_method_override.html\">window_object_method_override.html<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/window_object_method_override.html\" title=\"Click picture\">&#8220;proof of concept&#8221; web application<\/a> you can also <a href='#ifwom'>try below<\/a>.<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/window-object-method-override-return-values-tutorial\/'>Window Object Method Override Return Values Tutorial<\/a>.<\/p-->\n<hr>\n<p id='womott'>Previous relevant <a target=_blank title='Window Object Method Override Textbox Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/window-object-method-override-textbox-tutorial\/'>Window Object Method Override Textbox Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/window_object_method_override.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Window Object Method Override Textbox Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/window_object_method_override_textbox.jpg\" title=\"Window Object Method Override Textbox Tutorial\"  style=\"float:left;\"   \/><\/a><p class=\"wp-caption-text\">Window Object Method Override Textbox Tutorial<\/p><\/div>\n<p>Yesterday&#8217;s <a title='Window Object Method Override Primer Tutorial' href='#womopt'>Window Object Method Override Primer Tutorial<\/a>&#8216;s web application needed interactive entry to work.  There are many interactive entry methodologies available to web applications, but perhaps yesterday&#8217;s choice of &#8230;<\/p>\n<ul>\n<li>prompt Javascript popup window &#8230; approach is not ideal, it &#8220;doubling up&#8221; with the Window Object prompt method, only serving to add confusion, and so today, though we still offer a <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/window_object_method_override.html?popup=y\" title=\"prompt way\">prompt way<\/a>, the default way becomes &#8230;<\/li>\n<li>textbox<br \/>\n<code><br \/>\n&lt;input onblur=\"one=this.value;\" style=\"display:none;\" id=ione placeholder=\"one\" type=\"text\" value=\"\"&gt;&lt;\/input&gt;<br \/>\n&lt;input onblur=\"two=this.value;\" style=\"display:none;\" id=itwo placeholder=\"two\" type=\"text\" value=\"\"&gt;&lt;\/input&gt;<br \/>\n&lt;input onblur=\"three=this.value;\" style=\"display:none;\" id=ithree placeholder=\"three\" type=\"text\" value=\"\"&gt;&lt;\/input&gt;<br \/>\n&lt;input onblur=\"four=this.value;\" style=\"display:none;\" id=ifour placeholder=\"four\" type=\"text\" value=\"\"&gt;&lt;\/input&gt;<br \/>\n<br \/>\n&lt;select id=mysel onchange=\"<font color=blue>valnone();<\/font> setitup(this.value,'');\"&gt;<br \/>\n...<br \/>\n&lt;\/select&gt;<br \/>\n<\/code>\n<\/li>\n<\/ul>\n<p> &#8230; <font color=blue>supported by<\/font> Javascript code &#8230;<\/p>\n<p><code><br \/>\n  var one='', two='', three='', four='';<br \/>\n<br \/> <br \/>\n  function setitup(tv, newnewt) {<br \/>\n    var thisih='';<br \/>\n    var suff=';';<br \/>\n    var varsare=[], ivars;<br \/>\n    if (tv.indexOf('(') != -1 && tv.indexOf('()') == -1) {<br \/>\n      if (newnewt != '') {<br \/>\n      newt=newnewt;<br \/>\n      document.getElementById('myh4').style.backgroundColor='orange';<br \/>\n      } else {<br \/>\n      document.getElementById('myh4').style.backgroundColor='yellow';<br \/>\n      newt=template.replace(\/prompt\/g, tv.split('(')[0]).replace(\/one\\,two\/g, tv.split('(')[1].split(')')[0]);<br \/>\n      }<br \/>\n      vars=tv.split('(')[1].split(')')[0].split(',');<br \/>\n      for (ivars=0; ivars&lt;vars.length; ivars++) {<br \/>\n        <font color=blue>if (document.URL.indexOf('popup=') != -1) {<\/font><br \/>\n        thisih+=' ' + vars[ivars] + '=window.prompt(' + \"'Please enter value for \" + vars[ivars] + \"',''); \";<br \/>\n        <font color=blue>} else {<br \/>\n        document.getElementById('i' + vars[ivars]).style.display='block';<br \/>\n        if (newnewt == '') {<br \/>\n        document.getElementById('i' + vars[ivars]).value='';<br \/>\n        }<br \/>\n        thisih+=' document.getElementById(' + \"'i\" + vars[ivars] + \"'\" + ').value=' + \"'' + \" + vars[ivars] + ';   document.getElementById(' + \"'i\" + vars[ivars] + \"'\" + ').style.display=' + \"'block'\" + '; ';<br \/>\n        }<\/font><br \/>\n      }<br \/>\n      if (newt.indexOf(tv.split('(')[1].split(')')[0] + ')') != -1) {<br \/>\n      suff=newt.split(tv.split('(')[1].split(')')[0] + ')')[eval(-1 + newt.split(tv.split('(')[1].split(')')[0] + ')').length)].split('}')[0];<br \/>\n      }<br \/>\n      \/\/suff+=' valnone(); ';<br \/>\n      if (newt.indexOf('window.') != -1) {<br \/>\n      thisih+=' ' + newt.split('{')[1].split('window.')[0] + ' ' + tv.split('(')[0] + '(' + tv.split('(')[1].split(')')[0].trim() + ')' + suff + ' ';<br \/>\n      } else {<br \/>\n      thisih+=' ' + tv.split('(')[0] + '(' + tv.split('(')[1].split(')')[0].trim() + ')' + suff + ' ';<br \/>\n      }<br \/>\n      document.getElementById('myh4').innerHTML=\"&lt;a title='Double click to make happen' ondblclick=\\\"\" + thisih + \"\\\" style=text-decoration:underline;cursor:pointer;&gt;\" + newt + \"&lt;\/a&gt;\";<br \/>\n      eval(newt);<br \/>\n    }<br \/>\n  }<br \/>\n<br \/>\n  <font color=blue>function valnone() {<br \/>\n    document.getElementById('ione').style.display='none';<br \/>\n    document.getElementById('itwo').style.display='none';<br \/>\n    document.getElementById('ithree').style.display='none';<br \/>\n    document.getElementById('ifour').style.display='none';<br \/>\n  }<\/font><br \/>\n<\/code><\/p>\n<p> &#8230; in <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/Geographicals\/diff.php?one=http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/window_object_method_override.html-GETME\" title=\"window_object_method_override.html\">the changed<\/a> <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/window_object_method_override.html-GETME\" title=\"window_object_method_override.html\">window_object_method_override.html<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/window_object_method_override.html\" title=\"Click picture\">&#8220;proof of concept&#8221; web application<\/a> you can also <a href='#ifwom'>try below<\/a>.<\/p>\n<p><!--p>You can also see this play out at WordPress 4.1.1's <a target=_blank  href='\/\/www.rjmprogramming.com.au\/ITblog\/window-object-method-override-textbox-tutorial\/'>Window Object Method Override Textbox Tutorial<\/a>.<\/p-->\n<hr>\n<p id='womopt'>Previous relevant <a target=_blank title='Window Object Method Override Primer Tutorial' href='\/\/www.rjmprogramming.com.au\/ITblog\/window-object-method-override-primer-tutorial\/'>Window Object Method Override Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/window_object_method_override.html\"><img decoding=\"async\" style=\"border: 15px solid pink;\" alt=\"Window Object Method Override Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/window_object_method_override.jpg\" title=\"Window Object Method Override Primer Tutorial\"  style=\"float:left;\"   \/><\/a><p class=\"wp-caption-text\">Window Object Method Override Primer Tutorial<\/p><\/div>\n<p>Yesterday&#8217;s <a target=_blank title='Colour Wheel Prompt Override Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/colour-wheel-prompt-override-tutorial\/'>Colour Wheel Prompt Override Tutorial<\/a> <i>prompt<\/i><font size=1>ed<\/font> us <font size=1>(chortle, chortle)<\/font> to piece together a more generic look at &#8230;<\/p>\n<ul>\n<li><a target=_blank href='\/\/www.w3schools.com\/jsref\/obj_window.asp' title='https:\/\/www.w3schools.com\/jsref\/obj_window.asp'>window object methods<\/a> &#8230; and &#8230;<\/li>\n<li>override &#8230; ideas &#8230; merged into a &#8230;<\/li>\n<li>&#8220;proof of concept&#8221; web application<\/li>\n<\/ul>\n<p> &#8230; that might tweak some ideas and thoughts your way!  Try the Javascript DOM based <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/window_object_method_override.html_GETME\" title=\"window_object_method_override.html\">window_object_method_override.html<\/a>&#8216;s <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/window_object_method_override.html\" title=\"Click picture\">&#8220;proof of concept&#8221; web application<\/a> you can also try below &#8230;<\/p>\n<p><iframe id=ifwom src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/window_object_method_override.html\" style=\"width:100%;height:350px;\"><\/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='#d56190' onclick='var dv=document.getElementById(\"d56190\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/window\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d56190' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\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='#d56196' onclick='var dv=document.getElementById(\"d56196\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/method\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d56196' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\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='#d56200' onclick='var dv=document.getElementById(\"d56200\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/return\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d56200' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>It is somewhat true that Javascript does not care about the type of variable your non-array variable is, in the sense that &#8230; strings &#8230; and &#8230; (any of the forms of) integers or real numbers &#8230; can be &#8220;housed&#8221; &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/window-object-method-override-return-values-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,14,1,37],"tags":[1760,354,399,576,609,2780,652,1830,849,2010,875,1836,997,1761,1986,3420,3998,1675,1319,1583,3996,3997],"class_list":["post-56200","post","type-post","status-publish","format-standard","hentry","category-elearning","category-event-driven-programming","category-uncategorised","category-tutorials","tag-constant","tag-dom","tag-eval","tag-html","tag-input","tag-interactive-entry","tag-javascript","tag-method","tag-object","tag-object-oriented-programming","tag-oop","tag-override","tag-programming","tag-prompt","tag-proof-of-concept","tag-return","tag-return-value","tag-textbox","tag-tutorial","tag-window","tag-window-object","tag-window-object-method"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/56200"}],"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=56200"}],"version-history":[{"count":8,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/56200\/revisions"}],"predecessor-version":[{"id":56208,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/56200\/revisions\/56208"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=56200"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=56200"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=56200"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}