{"id":1701,"date":"2022-08-30T15:18:43","date_gmt":"2022-08-30T15:18:43","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/29\/modernizr-testing-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:18:43","modified_gmt":"2022-08-30T15:18:43","slug":"modernizr-testing-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/modernizr-testing-collection-of-common-programming-errors\/","title":{"rendered":"Modernizr testing-Collection of common programming errors"},"content":{"rendered":"<p>With yepnope prefixes, it&#8217;s possible to run predefined, named functions. Note: I have only tested this with latest chrome on OS X.<\/p>\n<p>However, for this to work, you will need a &#8220;dummy URL&#8221;, e.g., an image that you plan to load on the page (your logo is a good candidate).<\/p>\n<p>Also, because <code>Modernizr.load<\/code> only aliases the <code>yepnope.apply<\/code> method, you will need to refer to <code>yepnope<\/code> by name to add a prefix.<\/p>\n<pre><code>\/*globals window *\/\n(function (Modernizr) {\n    \"use strict\";\n    window.yepnope.addPrefix('function', function (resourceObj) {\n        var dummyUrl = 'static\/my_logo.png';\n        resourceObj.noexec = true;\n        window[resourceObj.url]();\n        resourceObj.url = dummyUrl;\n        return resourceObj;\n    });\n    \/\/ predefined functions\n    window.alert_support = function () {\n        window.alert('Supports it!');\n    };\n    window.alert_damn = function () {\n        window.alert('Oh, damn! This browser sucks!');\n    };\n    window.alert_boom = function () {\n        window.alert('boom');\n    };\n    \/\/ Modernizer.load is an alias for yepnope. See API at http:\/\/yepnopejs.com\/.\n    Modernizr.load([{\n        test: Modernizr.cssgradients,\n        yep: 'function!alert_support',\n        nope: 'function!alert_damn'\n    }, {\n        test: Modernizr.rgba,\n        yep: 'function!alert_boom'\n    }]);\n}(window.Modernizr));\n<\/code><\/pre>\n<p>Of course, if you don&#8217;t want to pollute the global <code>window<\/code> namespace, you could put your named functions in an object and change <code>window[resourceObj.url]();<\/code> to <code>window.MyObj[resourceObj.url]();<\/code>.<\/p>\n<p>The real power of this is that <code>callback<\/code> functions fire, the named functions can call <code>Modernizr.load<\/code> as well, and\/or you could write a more purposeful prefix than the generic function executor shown here.<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-29 06:07:12. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>With yepnope prefixes, it&#8217;s possible to run predefined, named functions. Note: I have only tested this with latest chrome on OS X. However, for this to work, you will need a &#8220;dummy URL&#8221;, e.g., an image that you plan to load on the page (your logo is a good candidate). Also, because Modernizr.load only aliases [&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-1701","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1701","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=1701"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1701\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1701"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1701"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1701"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}