{"id":1719,"date":"2022-08-30T15:18:52","date_gmt":"2022-08-30T15:18:52","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/29\/modernizr-load-a-b-seems-to-execute-b-before-a-how-is-this-possible-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:18:52","modified_gmt":"2022-08-30T15:18:52","slug":"modernizr-load-a-b-seems-to-execute-b-before-a-how-is-this-possible-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/modernizr-load-a-b-seems-to-execute-b-before-a-how-is-this-possible-collection-of-common-programming-errors\/","title":{"rendered":"Modernizr load [A, B] seems to execute B before A, how is this possible?-Collection of common programming errors"},"content":{"rendered":"<p>Modernizr.load({ both: [a, b] }) seems to executes <code>b<\/code> before <code>a<\/code> but that&#8217;s not how Modernizr is supposed to work? &#8220;<em>yepnope.js [used by Modernizr] always executes things in the order they are listed<\/em>&#8220;<\/p>\n<p>Modernizr versions 2.5.3 and 2.6.2.<\/p>\n<p>I&#8217;m loading angular.js and angular-sanitize.js like so:<\/p>\n<pre><code>Modernizr.load({\n  both: [\n    cdnDir + 'angular.js',\n    cdnDir + 'angular-sanitize.js',\n    d.i.assetsUrlPathStart + 'debiki-dashbar.js'],\n  complete: bootstrapAngular\n})\n<\/code><\/pre>\n<p>However, infrequently, <code>angular-sanitize.js<\/code> dies because <code>angular<\/code> does not yet exist.<\/p>\n<p>But isn&#8217;t <code>Modernizr.load(both: [a, b, c])<\/code> guaranteed to execute a, b, c in order? What is happening&#8230;?<\/p>\n<p><em><strong>Details:<\/strong><\/em><\/p>\n<p>The error happens on an <code>angular.extend(...)<\/code> line in angular-sanitize.js, the last line in this excerpt: (line 148)<\/p>\n<pre><code>\/\/ Elements that you can, intentionally, leave open (and which close themselves)\n\/\/ http:\/\/dev.w3.org\/html5\/spec\/Overview.html#optional-tags\nvar optionalEndTagBlockElements = makeMap(\"colgroup,dd,dt,li,p,tbody,td,tfoot,th,thead,tr\"),\n    optionalEndTagInlineElements = makeMap(\"rp,rt\"),\n    optionalEndTagElements = angular.extend({}, optionalEndTagInlineElements, optionalEndTagBlockElements);\n<\/code><\/pre>\n<p>Here&#8217;s the error message:<\/p>\n<blockquote>\n<p>Uncaught TypeError: Cannot call method &#8216;extend&#8217; of undefined ajax.googleapis.com\/ajax\/libs\/angularjs\/1.0.1\/angular-sanitize.js:148<\/p>\n<\/blockquote>\n<p>and Chrome&#8217;s debugger shows that <code>window.angular<\/code> is indeed undefined &#8211; althought it&#8217;s being used on the very last line in angular.js (which is supposed to be executed first of all).<\/p>\n<p>Chrome (version 24.0.1312.57) says that both angular.js and angualar-sanitize.js are loaded from the browser&#8217;s cache.<\/p>\n<p>Update: This more explicit rewrite really should work I think. But when run, it sometimes prints &#8220;Angular absent&#8221; and dies later on (when angular-sanitize.js runs)- although Angular &#8220;must&#8221; just have been created.<\/p>\n<pre><code>Modernizr.load({\n  load: cdnDir + 'angular.js', \/\/<\/code><\/pre>\n<p id=\"rop\"><small>Originally posted 2013-11-29 06:17:32. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Modernizr.load({ both: [a, b] }) seems to executes b before a but that&#8217;s not how Modernizr is supposed to work? &#8220;yepnope.js [used by Modernizr] always executes things in the order they are listed&#8220; Modernizr versions 2.5.3 and 2.6.2. I&#8217;m loading angular.js and angular-sanitize.js like so: Modernizr.load({ both: [ cdnDir + &#8216;angular.js&#8217;, cdnDir + &#8216;angular-sanitize.js&#8217;, d.i.assetsUrlPathStart [&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-1719","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1719","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=1719"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1719\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}