Good point. In fact, 'new' isn't just a reserved word, it's an operator!

Regarding these method calls:

> a.new(); // still fails in ie
> a.class(); // still fails in ie

If you have to, you can call methods with illegal names by using [] notation
instead of . notation:

    a['new']();
    a['class']();

You can even use property and method names with special characters this way:

    var a = {
        '!...@#$prop erty)()(': 'test',
        '** a method! Yes![]{}': function( value ) {
            alert( value );
        }
    };

    a['** a method! Yes![]{}']( a['!...@#$prop erty)()('] );

-Mike

> From: Kean
> 
> Alexandre,
> 
> Another word of caution. Do choose your labels carefully. 
> Avoid keywords.
> Adding quotes to keyword labels ensure compatibility with YUI 
> compressor.
> 
> var a = {
>       // new without quotes produce error in ie
>       "new": function() {
>               alert("new");
>       },
>       // class without quotes produce error in ie
>       "class": function() {
>               alert("class");
>       },
>       // YUI compressor won't compress if you have no quotes 
> on keywords
>       float: function() {
>               alert("float");
>       },
>       int: function(){
>               alert("int");
>       }
> }
> 
> a.new(); // still fails in ie
> a.class(); // still fails in ie
> a.float();
> a.int();
> 

Reply via email to