Posts

Bases, merits, and defects of packed code

How many times we have seen an included JavaScript apparently incomprehensible? These examples could explain better what I mean: packed.it via MyMin eval((function(M,i,n){return '0("1");'.replace(/\w+/g,function(m){return (n[m]!=i[m]&&i[m])||(i[m]=M[parseInt(m,36)])})})('alert.test'.split('.'),{},Object.prototype)) Dean Edwards packer eval(function(p,a,c,k,e,d){e=function(c){return c};if(!''.replace(/^/,String)){while(c--)d[c]=k[c]||c;k=[(function(e){return d[e]})];e=(function(){return'\w+'});c=1};while(c--)if(k[c])p=p.replace(new RegExp('\b'+e(c)+'\b','g'),k[c]);return p}('1('0');',2,2,'test|alert'.split('|'),0,{})) These are only two parsers which aim is to reduce code size using an inline decompression technique that is able to evaluate source code after common keywords replacement. Basis of portable and packed code The main goal of these services is to compress a source...

My 5 cents about JavaScript Prototypal Inheritance

Few days ago I read an interesting post about Simple JavaScript Inheritance . The most hilarious thing is that prototypal inheritance is truly simple, as John wrote, but there are still a lot of developers that do not probably understand perfectly them. In this link you can find an " all in one " page about JavaScript prototypal inheritcance and classical emulation. As I wrote at the end of that page, please do not hesitate to correct me if there is something wrong, or please ask me more details if there is something that is not so clear. Sorry for my not perfect yet English, and have fun with JavaScript. (happy easter too!)

How to inject protected methods in JavaScript - Part II

As a performances maniac, I've found another way to inject protected methods, or something similar, without unnecessary overload of each public method. Of course, precedent way is definitively more clear, linear, but if you have a constructor.prototype with a lot of private methods, the overload process will be a wall in front of method execution speed. Each time you will use a public method, you have to set, and unset, every protected method, and at the same time, as explained in my precedent post, you cannot send the object outside during public method execution, because it will expose every method, protected included. This new proposal is based on a Function like strategy, applied to instances: apply, and call. Please have a look at this prototype function: function prototype(constructor, public, protected){ // webreflection - mit style if(protected){ public.apply = function(callback, arguments){ return (callback.charAt(0) === "_" ? protected : this)[callback]....

ABC - Ajax Basic Call

I know everyone uses incredibly cool libraries that do everything in few lines, and 30 or more Kb ... but do you always need all this stuff for simple Ajax interactions? The JavaScript ninja secret is to create everything ad hoc, where everything will be under control and will be extremely optimized and, why not, fast. ABC goals is to let you use, simply, Ajax. What is Ajax in few words? The possibility to send and recieve data, usually using GET, POST, or both method (POST with a query stirng). That's exactly what you can do with ABC, and these are major features: simple, fast, lightweight ... probably the only function you need for 80% of Ajax tasks unobtrusive, does not change, create, modify ... absolutely nothing IE cache safe, forget IE cache problems without effort array compatible, send single dimensional arrays too easily integrable, using around your own cool code to send entire forms or whatever you need quick but not dirty, and without global scope paranoia ... one fun...

Do You Like Browser Benchmarks? Here I am!

Hi guys, today we will not talk about my last JavaScript ArrayObject creation :D Today is the benchmark day, and in this case the test is as simple as explicative ... both Math object and scope are two things we use every day for whatever purpose in this baby Web 2.0 era! Let me start directly with results (ORDER BY speed ASC): Firefox 3.0b4 ---------------------------------- regular avg time in ms: 9.98 scoped avg time in ms: 3.18 encapsulated avg time in ms: 12.98 Safari 3.0.4 (523.15) ---------------------------------- regular avg time in ms: 13.42 scoped avg time in ms: 6.42 encapsulated avg time in ms: 11.82 Opera 9.24 ---------------------------------- regular avg time in ms: 13.82 scoped avg time in ms: 9.6 encapsulated avg time in ms: 17.64 Internet Explorer 8.0.6001.17184 ---------------------------------- regular avg time in ms: 16.42 scoped avg time in ms: 6.82 encapsulated avg time in ms: 16.82 Firefox 2.0.0.12 ---------------------------------- regular avg time in ms: 26....

Sorry Dean, I subclassed Array again

Most library authors would love to extend the Array object (especially for those tasty iteration methods) but shy away from doing so for fear of breaking other scripts. So nearly all (with the noteable exception of Prototype) leave Array and other built-in objects alone. This is how Dean Edwards started one of his (historic) post about subclassing Array , but I finally found the way to do it better, and You'll read why and how ... please be patience :D The nightmare does not come only from IE We all know how weird is Internet Explorer when you try to use an array as a constructor prototype. What you probably do not know yet, is that IE is the only one that gives you problem " instantly instead of during ". Let's start with the first, basic example: // FireFox and Safari, plus IE, why not function MyArray(){}; MyArray.prototype = []; /** this should be a must ... however, who cares about that ... MyArray.prototype.constructor = MyArray; */ var ma = new MyArray; ma.push...

Jaxer and packed.it ... not possible yet

Unfortunately, my experience with Jaxer has been really cool but this project is too young to be used as a server side project, and this is only my opinion. First of all, the simple File API is great, but if you look for binary safe in the search form, you'll be redirect in an empty page ... quite hilarious, isn't it?! Anyway, I did not test the file.open("wb") mode, probably it's working, probably not ... who care about that? Me, because to pre compile packed.it projects using MyMin and then Zlib I need to write in binary mode ... no way guys! At the same time, there's not a true bridge for Java, at least that what I was looking for, since Jaxer could be integrated with TomCat, I wonder what are they waiting for to create an easy interface to call directly Java, or whatever mature server language you want. It will be an extreme start up improvement for your project, what's not possible yet, will be with some Java, Mono, Python, Ruby, PHP, or whatever is...