Posts

Showing posts from March, 2008

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...

Turbo ArrayObject

Today I am more clever than two days ago :lol: ... that's why ArrayObject has now a turbo compressor, specially with those methods that do not require an intermediate wrapper: every forEach indexOf join lastIndexOf pop push reverse shift some These methods, if susported (if not use JSLRevision ;)), works directly in core. The result is that every Array like instance now are more fast than ever, considering that join, pop, push, reverse, indexOf, shift, and forEach are widely used in a lot of projects. This object could be the core for libraries like jQuery, or other that emulates array behaviour ... and I solved problems with sort plus some minor fix. It has been successfully tested in FireFox, IE, Safari, and Opera. Seems cool? I hope so :geek:

JavaScript ArrayObject

I think this constructor could be a good start point for a lot of projects. We know that IE has problems while it try to extend an array, disabling length modification. That's why I have created this wrapper that does not require weird strategies (e.g. iframe with a different enviroment) and works with a wide range of browsers. Honestly, I did not test performances against pure arrays, but I did everything to make code as fast as possible, using good practices and creating an in-scope shortcut for the Array.prototype. Have a look here if you are interested in this constructor, ignore them if you do not think this is a good idea :) P.S. Please note that this constructor does not care about missed prototypes, it only does its wrapping work and nothing else. To improve Array compatibility and methods, please remember my JSL Revision . Including them in your page, You'll not have problems with every ArrayObject method, eccept for reduce and reduceRight (I will create a good implem...