[v2-132] How to initialize an object in a classic way?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

[v2-132] How to initialize an object in a classic way?

Post by arcticir » 24 Apr 2021, 10:13

The v2 upcoming beta news is exciting :D , so I started to learn the new V2 syntax.
But what makes me painful is that I can no longer use objects as before {"&":"b"}, the only solution is map("&","b"). But I think I hate it, I hate a, b, c, d, I like the well-structured a: b, c: d
How to initialize an object using classic methods?



======
I'm very sorry, I sent it in the wrong place. I request the administrator to transfer this post to "Ask For Help". :o
Last edited by gregster on 24 Apr 2021, 10:16, edited 1 time in total.
post
Posts: 4
Joined: 21 Apr 2021, 12:59

Re: [v2-132] How to initialize an object in a classic way?

Post by post » 24 Apr 2021, 11:08

Objects can still be created literally I think, have you tried it?

Code: Select all

obj := { boo:"rah", tee:"noh" }

msgbox(obj.boo)
msgbox(obj.tee)
gregster
Posts: 9001
Joined: 30 Sep 2013, 06:48

Re: [v2-132] How to initialize an object in a classic way?

Post by gregster » 24 Apr 2021, 11:15

arcticir wrote:
24 Apr 2021, 10:13
I'm very sorry, I sent it in the wrong place. I request the administrator to transfer this post to "Ask For Help". :o
I already did it for you. No worries. I think it is now where it is was meant to be, in the v2 help subforum... (originally, it was in 'Scripts and Functions')
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: [v2-132] How to initialize an object in a classic way?

Post by swagfag » 24 Apr 2021, 11:35

and how were u "using objects as before {"&":"b"}"? im not gonna bother firing v1 up, but surely not obj.& which im fairly certain wont even compile - u had to do obj["&"], ie "the Map usage", so just use a map then
arcticir wrote:
24 Apr 2021, 10:13
I think I hate it
ull learn to love it. if the globalists say this about owning nothing, i think ull manage an exception for a small part of ahk just fine ;)
arcticir
Posts: 694
Joined: 17 Nov 2013, 11:32

Re: [v2-132] How to initialize an object in a classic way?

Post by arcticir » 24 Apr 2021, 22:10

@post In the original version where obj was divided into arr-map, {"&":1,"&":2} is still feasible.

@gregster Thanks.

@swagfag It seems that it will take me a while to get used to the new grammar.
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: [v2-132] How to initialize an object in a classic way?

Post by TheArkive » 27 Apr 2021, 12:39

@arcticir
Also, if you need to iterate through the AHK v2 {obj} then you can use the following loop:

Code: Select all

obj := {item:"value", item2:"value2"}

For prop, val in obj.OwnProps()
	msgbox(prop " = " value)
Post Reply

Return to “Ask for Help (v2)”