Never understood the reason for "use strict" and even less do I understand why to use this "use restrict", can we not start coding properly ? ;-) but hey !!, I think it's good tool to check your code if you are really picky and don't like loose operators.

On 28/03/11 16:48, Olov Lassus wrote:
On Mar 28, 12:56 pm, Nick Morgan<[email protected]>  wrote:

I don't see how you're enforcing this. What about:

function foo(x) {
    return x<  5;

}
How do you ensure/check that the correct
types are used?
By dynamic program analysis, not static.

The restricter tool will convert your function into this (note that it
preserves whitespace and comments):
function foo(x) {
    return __lt(x, 5);

}

You'll then run this together with restrict-mode.js, which is a
prelude implementing functions such as __lt:
function __lt(x, y) {
     var xtype = typeof x;
     var ytype = typeof y;

     if (xtype === ytype) {
         if ((xtype === "string" || xtype === "number")) {
             return /*@loose*/(x<  y);
         }
     }
     __throw_typeerror("<", x, y);
}

While the<  operator is easy to rewrite directly into a funcall,
others (such as postfix ++) are more complex. You can enter source
code on http://restrictmode.org/try/ and check out both how it gets
rewritten and how it executes.

/Olov


--
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to