Monday, March 17th, 2008

ProtoSafe Eases Compatibility for Prototype

Category: Prototype

With so many new components being developed in a variety of different of JavaScript libraries, it’s a natural expectation that sooner or later, you’re going to want to mix and match these components within your application. Sometimes though, it’s not that easy due to architectural conflicts between different libraries. John David Dalton set out to minimize this pain via his new project called ProtoSafe.

I started ProtoSafe in response to a couple of posts on the Prototype Core Mailing list written by developers frustrated with Prototype’s 3rd party compatibility issues. I did some digging and found a post my Mislav Marohnic (here) explaining an easy way to keep Prototype out of the global namespace by simply wrapping everything in a self-executing anonymous function.

I asked John to explain the best use case for Protosafe and how it helps:

Prototype extends native data type prototypes which makes it very convenient for the developer but when interacting with 3rd party code not written for Prototype, these prototype extensions can cause compatibility issues. The most common is the Array for-in loop issue where by doing a for in loop over an array you get its indexed values plus the method names of all the added helper methods.

The benefit that ProtoSafe provides is that it allows Prototype to be used alongside 3rd party code without causing these compatibility issues.
Also it can be run against multiple frameworks which is good in the widget environment.

The demo page shows MooTools,Prototype,Dojo,YUI,jQuery all running on the same page.

Some highlights of ProtoSafe are:

  • It allows Prototype to work with 3rd-party scripts (no Array for-in
    loop pollution).
  • It works with Prototype 1.4-1.6.0.2.
  • Custom Packer3 that supports Prototype 1.6+/Scripty 1.8.1+
  • Only 3kb gzipped, less when compiled into the standalone js.

Posted by Rey Bango at 10:41 am
9 Comments

++++-
4.5 rating from 68 votes

9 Comments »

Comments feed TrackBack URI

Google Code Page:
http://code.google.com/p/protosafe/

Comment by jdalton — March 17, 2008

Wow. This is excellent. Great work, JDD.

Comment by PaulIrish — March 17, 2008

This doesn’t mean you can use for-in loops for Arrays again, people. ;)

Comment by Mislav — March 17, 2008

Well you can use for-in loops if you know what you’re doing. Check that the current property is not part of the prototype if you want to crawl the properties of an instance ( and not of the Object itself ).

Comment by p01 — March 18, 2008

Heheh Guys, you are missing the point. I am not recommending everyone start using arrays in for-in loops. I am saying if you use ProtoSafe then Prototype WILL work with 3rd-party code that DOES use arrays in for-in loops . It’s a GOOD thing :)

Comment by jdalton — March 18, 2008

my only thought is that the demo needs to use the word “embiggen” and not “embolden”, if only for full simpsons compliance.

Comment by slightlyoff — March 19, 2008

French internet company located in French Riviera and specialized in online services is searching for :
A senior Web 2.0 Developer (freelance)
Required skills :Web 2.0/Javascript/Ajax/Prototype.js
Expert-level knowledge of LAMP, Javascript, Ajax, and related application development,
Knowledges in cross browser development (IE, Firefox)
Salary : Competitive, based on skills and expérience
To apply, please sent your job application to : atricot@oodesk.com

Comment by leselles — April 1, 2008

OpenAjax Hub 1.1 from OpenAjax Alliance addresses this kind of interoperability issues.

What about joining efforts?

Comment by samaxes — April 27, 2008

Can anyone post a download link anymore? He abandoned the project without a trace and none of the files remain. Please anyone?

Comment by coder12 — July 13, 2010

Leave a comment

You must be logged in to post a comment.