Posts

Showing posts with the label injection

Simulate Script Injection Via Data URI

Well, not only downloads on the fly , the data uri works for almost everything ( only iOS 5 beta does not want to work with inline data uri AUDIO sources .... but this is another story ... ) ... so ... How To Simulate Script injection Let's say you want a test but you don't want to bother a server. However, you want to be sure the test is asynchronous and it simulates the server. var head = document.getElementsByTagName("head")[0], script = document.createElement("script") ; head.insertBefore(script, head.lastChild); script.src = "data:text/javascript;base64," + btoa( "alert('Hello World')" ); How To Simulate JSONP Same trick, isn't it? ... except: script.src = "data:text/javascript;base64," + btoa( "callback(" + JSON.stringify(dummyData) + ")" ); How To Drop Server Requests well, this is the tricky one ... Surely there is some job to do in the createResponse() function but ... he...

Constructorification

... he he, I know the title could not be worst, but after my last post about Arrayfication I have thought: " ... hey, the Thing.ify(object) could be more than handy in many occasions such mixins and duck typing ... ". So, let me introduce the Function.prototype method that nobody will ever use: Function.prototype.ify = function (o) { for (var self = this, p = self.prototype, // find a fucking way to implement this in ES3 // ... uh wait, there's no way to implement // this in ES3 ... // https://bugzilla.mozilla.org/show_bug.cgi?id=518663 m = Object.getOwnPropertyNames(p), i = m.length, n; i--; ) { // methods only m[i] = typeof p[n = m[i]] == "function" ? "o." + n + "=p." + n + ";" : "" ; } m.push("return o"); return (self.ify = Function("p", "return function " + ...