{} restricted keywords

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

{} restricted keywords

Tony Polinelli

In js, when we are setting attribs to a div they need to be sent in an anonymous object {}. The issue is that we need to set 'class' often. I know that this is a keyword, and thats why it doesnt work as vars etc-

With anonymous objects we can Reflect 'class' onto it - seeing as they are empty objects this shouldnt conflict with anything - would there be a way to allow for this without Reflection?

--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: {} restricted keywords

Mark de Bruijn | Dykam
Keyword availability would be nice in haXe. This could possibily be done by some escape char, where every confusing use is escaped. It makes it also possible to use classnames as property. In case of @ as escape char: public var @Xml:Xml;

On Fri, Sep 11, 2009 at 3:19 AM, Tony Polinelli <[hidden email]> wrote:

In js, when we are setting attribs to a div they need to be sent in an anonymous object {}. The issue is that we need to set 'class' often. I know that this is a keyword, and thats why it doesnt work as vars etc-

With anonymous objects we can Reflect 'class' onto it - seeing as they are empty objects this shouldnt conflict with anything - would there be a way to allow for this without Reflection?

--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org



--
Mark

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: {} restricted keywords

Nicolas Cannasse
In reply to this post by Tony Polinelli
Tony Polinelli a écrit :
>
> In js, when we are setting attribs to a div they need to be sent in an
> anonymous object {}. The issue is that we need to set 'class' often. I
> know that this is a keyword, and thats why it doesnt work as vars etc-
>
> With anonymous objects we can Reflect 'class' onto it - seeing as they
> are empty objects this shouldnt conflict with anything - would there be
> a way to allow for this without Reflection?

keywords are keywords, they are useful to disambiguate the language
syntax. One possibility would be use _class and do the appropriate
removal of the "_" in your code which process the anonymous object.

Nicolas

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: {} restricted keywords

clemos
In reply to this post by Tony Polinelli
The recommanded way to manipulate an element's class attribute is
through the "className" property, I think.
Doesn't it solve your problem ?

It's true that "JSON"-like solution could eventually solve keyword
conflicts, like :
var attributes = { "class" : "myClass" };
trace( attributes["class"] );

+++++++
Clément

On Fri, Sep 11, 2009 at 3:19 AM, Tony Polinelli <[hidden email]> wrote:

>
> In js, when we are setting attribs to a div they need to be sent in an
> anonymous object {}. The issue is that we need to set 'class' often. I know
> that this is a keyword, and thats why it doesnt work as vars etc-
>
> With anonymous objects we can Reflect 'class' onto it - seeing as they are
> empty objects this shouldnt conflict with anything - would there be a way to
> allow for this without Reflection?
>
> --
> Tony Polinelli
> http://touchmypixel.com
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: {} restricted keywords

Adrian Veith
In reply to this post by Tony Polinelli
I have written a wrapper class for jquery. With it you have full access
to the jquery syntax (slightly changed to match HaXe needs):

for example:

in HaXe:

JQuery.Qy('#myid').AddClass('foo');


will translate to js:

jQuery('#myid').addclass('foo');

I will publish the code on lib.haxe

Cheers, Adrian.

Tony Polinelli schrieb:

>
> In js, when we are setting attribs to a div they need to be sent in an
> anonymous object {}. The issue is that we need to set 'class' often. I
> know that this is a keyword, and thats why it doesnt work as vars etc-
>
> With anonymous objects we can Reflect 'class' onto it - seeing as they
> are empty objects this shouldnt conflict with anything - would there
> be a way to allow for this without Reflection?
>
> --
> Tony Polinelli
> http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: {} restricted keywords

Tarwin Stroh-Spijer
@Adrian: Thanks for the wrapper, just to let you know there is already one out there. I do like the fact that you're accessing it through a static rather than something like 'new JQuery("xxx")' each time. I do think you should stick to the first letter lower-case convention which is normally used with haXe as otherwise it can just confuse the wider community.

@clemos: The example that Tony was pointing out was when using JQuery DOM creators that use anonymous objects to create DOM objects. It's fine with most properties of a DOM element ie "id" or "name" but with the very commonly used property of "class" you have to do the insane Reflect method. This is more than annoying as you can't string statements together property and the set "class" later as they're mostly anonymous.

@Nicolas: I'm sure you're right, "keywords are keywords", but I don't quite get why. I get in a lot of circumstances you don't wan to be using keywords for property names and such but as "keys" on an anonymous object it just seems to me you should not be restricted. I guess it's just not wanting to complicate the compiler and such which I totally understand. A compromise would be to be able to specify properties with quotes ie:

     var htmlNode = {"class": "highlightButton", name: "myHighlighter"};

Would this necessarily be a problem?

I do understand the suggestion of making the wrapper do the work of converting "_class" (and I guess for all keywords) to "class" but I think this is a lot less intuitive. Seeing as anonymous object CAN have a property which is a keyword it seems to make sense to be able to make them with that keyword?

@Mark: I don't see this as a bad idea. Guess it could get confusing though in certain circumstances. If it was implemented though I'd prefer to use something such as backtick quoing ie "public var `class`:String" - but that could just be because I've used that lots in SQL for the same reason.


Tarwin Stroh-Spijer
_______________________

Touch My Pixel
http://www.touchmypixel.com/
phone: +61 3 8060 5321
_______________________


On Fri, Sep 11, 2009 at 6:26 PM, Adrian Veith <[hidden email]> wrote:
I have written a wrapper class for jquery. With it you have full access
to the jquery syntax (slightly changed to match HaXe needs):

for example:

in HaXe:

JQuery.Qy('#myid').AddClass('foo');


will translate to js:

jQuery('#myid').addclass('foo');

I will publish the code on lib.haxe

Cheers, Adrian.

Tony Polinelli schrieb:
>
> In js, when we are setting attribs to a div they need to be sent in an
> anonymous object {}. The issue is that we need to set 'class' often. I
> know that this is a keyword, and thats why it doesnt work as vars etc-
>
> With anonymous objects we can Reflect 'class' onto it - seeing as they
> are empty objects this shouldnt conflict with anything - would there
> be a way to allow for this without Reflection?
>
> --
> Tony Polinelli
> http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org