{"id":28820,"date":"2017-03-14T03:01:19","date_gmt":"2017-03-13T17:01:19","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=28820"},"modified":"2017-03-12T20:41:09","modified_gmt":"2017-03-12T10:41:09","slug":"binding-javascript-settimeout-arguments-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/binding-javascript-settimeout-arguments-primer-tutorial\/","title":{"rendered":"Binding Javascript setTimeout Arguments Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/argument_to_setTimeout.html\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"Binding Javascript setTimeout Arguments Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/argument_to_setTimeout.jpg\" title=\"Binding Javascript setTimeout Arguments Primer Tutorial\"   \/><\/a><p class=\"wp-caption-text\">Binding Javascript setTimeout Arguments Primer Tutorial<\/p><\/div>\n<p>At this blog, with Javascript work, we like using <a target=_blank title='Javascript scope of variables discussion at w3schools' href='https:\/\/www.w3schools.com\/js\/js_scope.asp'><i>global<\/i><\/a> variables, in particular the global variables defined at or near the top of (Javascript) scripting, and existant from then on.  However, the use of global variables is not popular in many coding schools I guess because it is less user friendly as far as understanding the code goes, (we guess again) because the initialization of the global variable is likely to occur out of the view of the coding work you are involved in (perhaps) 90% of the time, for any coding of any length, that is (and using your usual text editor screen).<\/p>\n<p>So, what about some discipline regarding reducing (Javascript) global variable usage, and still doing some of those favourite things you like to do, that if you are anything like me, might include (the wonderful, the stupendous, the endlessly <a target=_blank title='Schweppervescence' href='https:\/\/www.youtube.com\/watch?v=Gn52eThyTwQ'>refreshing<\/a> <font size=1>&#8230; sheep grazier&#8217;s alert &#8230; repeated joke &#8230; repeated bubbles <\/font><font size=2>&#8230; see you on the foul line<\/font>) &#8230;<\/p>\n<p><code><br \/>\n<a target=_blank title='Javascript setTimeout method information from w3schools' href='http:\/\/www.w3schools.com\/jsref\/met_win_settimeout.asp'><i>setTimeout<\/i><\/a><br \/>\n<\/code><\/p>\n<p> &#8230; timer functionality (that&#8217;s Batman, and Robin is <a target=_blank title='Javascript setInterval method information from w3schools' href='http:\/\/www.w3schools.com\/jsref\/met_win_setinterval.asp'><i>setInterval<\/i><\/a>)?<\/p>\n<p>Well, we did some research on this, and came upon this great advice <a target=_blank title='Useful webpage, thanks' href='http:\/\/stackoverflow.com\/questions\/1190642\/how-can-i-pass-a-parameter-to-a-settimeout-callback'>webpage<\/a>, thanks, that got me onto using (the Javascript method) &#8230;<\/p>\n<p><code><br \/>\n[functionName].<a target=_blank title='Javascript bind method information' href='http:\/\/stackoverflow.com\/questions\/2236747\/use-of-the-javascript-bind-method'>bind()<\/a><br \/>\n<\/code><\/p>\n<p>Today, exploring this idea, we&#8217;ve got this very simple counter going on with a small HTML and Javascript web application, devoid of global variables, and using a <a target=_blank title='Javascript setTimeout method information from w3schools' href='http:\/\/www.w3schools.com\/jsref\/met_win_settimeout.asp'><i>setTimeout<\/i><\/a> scenario that passes in arguments to the function, using [functionName].<a target=_blank title='Javascript bind method information' href='http:\/\/stackoverflow.com\/questions\/2236747\/use-of-the-javascript-bind-method'>bind()<\/a> methodologies.  It is called <a target=_blank title='argument_to_setTimeout.html' href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/argument_to_setTimeout.html_GETME'>argument_to_setTimeout.html<\/a> that you could peruse, or try out via this <a target=_blank title='Click picture' href='http:\/\/www.rjmprogramming.com.au\/HTMLCSS\/argument_to_setTimeout.html'>live run<\/a> link.<\/p>\n<p>We&#8217;re hoping this might be a piece in a jigsaw of coding issues that helps you out.<\/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='#d28820' onclick='var dv=document.getElementById(\"d28820\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/tag\/settimeout\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d28820' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>At this blog, with Javascript work, we like using global variables, in particular the global variables defined at or near the top of (Javascript) scripting, and existant from then on. However, the use of global variables is not popular in &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/binding-javascript-settimeout-arguments-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,37],"tags":[1885,2152,576,652,997,1125,1126,1282,1319],"class_list":["post-28820","post","type-post","status-publish","format-standard","hentry","category-elearning","category-tutorials","tag-argument","tag-bind","tag-html","tag-javascript","tag-programming","tag-setinterval","tag-settimeout","tag-timer","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/28820"}],"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=28820"}],"version-history":[{"count":5,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/28820\/revisions"}],"predecessor-version":[{"id":28825,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/28820\/revisions\/28825"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=28820"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=28820"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=28820"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}