{"id":4429,"date":"2014-03-30T10:55:10","date_gmt":"2014-03-30T10:55:10","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/problem-about-shadowing-collection-of-common-programming-errors\/"},"modified":"2014-03-30T10:55:10","modified_gmt":"2014-03-30T10:55:10","slug":"problem-about-shadowing-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/problem-about-shadowing-collection-of-common-programming-errors\/","title":{"rendered":"problem about shadowing-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/6c13bf9cfcead87d332701ff860fbc84?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nS.L. Barth<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/0df2f3c2d3b43605889eb90231fb6884?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMatt Ball<br \/>\njavascript shadowing<br \/>\nI&#8217;ve been using jQuery and YUI side-by-side with no issues until recently. Occasionally, inside of a callback for, say, a YUI button, $ will be shadowed by some other function (click for big version):and for the life of me, I cannot figure out why this is happening. Yes, I know I could be safe and use jQuery or window.$ everywhere instead of just $, but that&#8217;s just a workaround and not an actual fix.At runtime, how can I find where this $ impostor is coming from? &#8211; e.g. find where it&#8217;s declared,<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/QQycm.jpg?s=32&amp;g=1\" \/><br \/>\nDog<br \/>\nerlang shadowing<br \/>\nI have a simple car process implemented in Erlang:-module(cars). -compile(export_all).-record(state, {count=1}).make_car() -&gt;spawn_link(fun() -&gt; car_proc(#state{}) end).car_proc(S) -&gt;receive{idle, X} -&gt;io:format(&#8220;idling for ~p second(s)~n&#8221;, [X]),timer:sleep(X*1000);{move, {X,Y}} -&gt;io:format(&#8220;move; x=~p, y=~p~n&#8221;, [X,Y]);{stop, Reason} -&gt;X = S#state.count,io:format(&#8220;stopped with count ~p because ~p~n&#8221;, [X+1, Reason])end,X = S#state.count,car_proc(S#state{count=X+1}).I can make it<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/41910a452554b187d044c00c576866b1?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nKevin Burke<br \/>\njavascript shadowing<br \/>\nIn the following code snippet I declare a global variable and then check for its presence inside a function.&lt;script&gt; x = 5; $(function() {var x = x || 3;console.log(x); \/\/ prints 3 }); &lt;\/script&gt;This behaves differently: &lt;script&gt; x = 5; $(function() {var y = x || 3;console.log(y); \/\/ prints 5 }); &lt;\/script&gt;I expect that in the first example, the variable declaration in the inner scope will detect that x already exists in the global scope, and take its value. Why does the fi<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/766ebbbe59ec9cccbda18827efe245f9?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nBeachRunnerFred<br \/>\njavascript variables shadowing<br \/>\nConsider the following piece of code: &lt;html&gt;&lt;head&gt;&lt;\/head&gt; &lt;body&gt;&lt;script type=&#8221;text\/javascript&#8221;&gt;var outside_scope = &#8220;outside scope&#8221;;function f1() {alert(outside_scope) ;}f1();&lt;\/script&gt; &lt;\/body&gt; &lt;\/html&gt;The output for this code is that the alert box displays the message &#8220;outside scope&#8221;. But, if I slightly modify the code as: &lt;html&gt;&lt;head&gt;&lt;\/head&gt; &lt;body&gt;&lt;script type=&#8221;text\/javascript&#8221;&gt;var outside_scope = &#8220;outside scope&#8221;;functi<\/li>\n<\/ul>\n<p>Web site is in building<\/p>\n","protected":false},"excerpt":{"rendered":"<p>S.L. Barth Matt Ball javascript shadowing I&#8217;ve been using jQuery and YUI side-by-side with no issues until recently. Occasionally, inside of a callback for, say, a YUI button, $ will be shadowed by some other function (click for big version):and for the life of me, I cannot figure out why this is happening. Yes, I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4429","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4429","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4429"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4429\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4429"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4429"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}