prototypal inheritance concept in javascript as a prototype based language

Classical inheritance is about extending types of things. Say you have a class, like Bike. When you want extend the behaviour, you have to design a new type of bike (like MotorBike). It’s like building a factory – you make lots of blueprints, and blueprints that reference those blueprints, but in order to ride one … Read more

Load javascript async, then check DOM loaded before executing callback

What you need is a simple queue of onload functions. Also please avoid browser sniffing as it is unstable and not future proof. For full source code see the [Demo] var onload_queue = []; var dom_loaded = false; function loadScriptAsync(src, callback) { var script = document.createElement(‘script’); script.type = “text/javascript”; script.async = true; script.src = src; … Read more

document.createElement(‘script’)… adding two scripts with one callback

I propose you to use some small loader which will chain and do stuff for you. For example like this one: function loadScripts(array,callback){ var loader = function(src,handler){ var script = document.createElement(“script”); script.src = src; script.onload = script.onreadystatechange = function(){ script.onreadystatechange = script.onload = null; handler(); } var head = document.getElementsByTagName(“head”)[0]; (head || document.body).appendChild( script ); … Read more

Prototype AJAX request being sent as OPTIONS rather than GET; results in 501 error

Too many hours looking for a correct fix on prototypejs… finally, we have a non-intrusive solution on great kourge (Wilson Lee) article!. Here is an excerpt: Most major Ajax frameworks like to set custom HTTP headers on the Ajax requests you instantiate; the most popular header is X-Requested-With: XMLHttpRequest. Consequently your request is promoted to … Read more

Ajax Binary Response

It might not be possible to stream binary data, but you can use Ajax to retrieve binary data. This is possible using one of two methods: Javascript Typed Arrays or an XMLHttpResponse overrideMimeType hack. Have a read of a good article on MDN – these examples are taken from there: Sending and Receiving Binary Data … Read more