Posts

Showing posts from May, 2007

JavaStrict Act III - Documentation and official 1.0 Release

My JavaScript Strict Type AS 2.0 like proposal now has a dedicated documentation page with some example code for each function or public static method too. The big limit in this " IE yet loosing users but persists " era is that native DOM nodes aren't usable as return value or arguments on cross-browser libraries, " just " for FireFox, Safari or Opera, where each node has its specified constructor and where Window is a valid constructor too. I'm yet waiting for your feedbacks, expecially from some Dojo Toolkit developer ... shouldn't Strict function be useful to write better code removing a lot of comments from your unpacked sources? I hope so :-) Update 2007-05-27 Alex Russell asked me a better example to understand why JavaStrict should be a good Dojo implementation. This is just a quick and simple example on how src/json.js file should be: dojo.json = { jsonRegistry: new dojo.AdapterRegistry(), register:Strict(Void, function(name, check, wrap

JavaStrict Act II - AS2.0 like Strict Type with JavaScript

I've just updated my JavaStrict public, static, function. It has been successfully tested with different cases and now it behaviour is like ActionScript 2.0 With this function , and dedicated Strict shortcut one, You can: define a return type, using a specific constructor or Void , if function mustn't return any kind of variable (null too) define one or more argument constructor, using specified constructor or Void if function mustn't accept any kind of parameter (null too) use a generic Object constructor, as returned or accepted instance if You don't know what kind of object function, r method, will accpet or return You can use Object for DOM elements too, expecially with Internet Explorer (6 or lower) where DOM Elements are typeof "object" but aren't instances of Object. Object is the super incoming or outgoing value type, it can be null or every kind of instance (obviously, Void is not Object, so You can't use Object to return Void values and vice-

JavaStrict - Strict Type arguments / returned values with JavaScript

I've just uploaded on devpro my last experimental (stable) function, called JavaStrict. What is JavaStrict goal? JavaStrict allows developers to add Strict Type in every kind of function or method, with or without prototype. Strict Type should be used for function arguments or for its returned value. JavaStrict static methods just create a function wrapper that will check automatically if arguments or returnValue are exactly specified instances. How does JavaStrict work? JavaStrict function has 3 public static methods: apply , to set Type of each accepted argument using an array as second one call , to set one or more valid Type manually returnValue , to set a valid returned value Type Examples // showMe is a basic function function showMe(str){ alert(str); }; // I need that single argument is a string instance // (new String("abc") or "abc" works correctly) showMe = JavaStrict.call(showMe, String); // test them try { showMe("Hello Strict!"); // Ok

Joking with JavaScript constructors

This object is Rhino on Cocoon Flow.js Ready (if it's configured to don't use code evaluation using eval), have fun with crazy inheritances and constructors :) var Instance = { /* Description: creates a new instance of specified constructor using second parameter as constructr arguments. This is just a New method alias. Example: var str = Instance.Create(String, ["Hello World"]); Arguments: Function instance constructor Array constructor arguments or empty array Returns: Object new instance of specified constructor */ Create:function(){ return this.New.apply(this, arguments); }, /* Description: creates a new instance of last specified constructor and extends them with every precedent constructor, if present. Each constructor need to have a dedicated array (empty too) to use them as its arguments. Example: function String2(){ this.trim = function(){ return this.replace(/^\s+|\s+$/g, ""); }; }; var str = Ins