- Get a-1, b-2, c-3, "d"-4.
Code: Select all
d="d" o:={a:1,"b":2,("c"):3,(d):4}
Can Initialize key-value which key contains quotation marks (like "d") directly in Object Constructors {}
In V2, can use t:={'"a"':1}. - Can support mix Object Constructors with Simple Arrays, Associative Arrays?
Like static o:={0:"a","b","c",4:"e","f",m:n}, so the b/c's index is 1/2, and e's index is 4, f's is 3(more flexible!) or 5?
The purpose is here at 3#.
[Vetoed]Object Constructors {} key with quote/mix array&key
[Vetoed]Object Constructors {} key with quote/mix array&key
Last edited by RobertL on 28 Aug 2014, 00:30, edited 4 times in total.
我为人人,人人为己?
Re: Object Constructors {} key with quotation/mix array & ke
You can if you override the built-in function Object(), although there's no way of detecting on how the keys-values were passed(where the mix starts/end, etc.) as the function will receive them as parameters.
But why do this?
But why do this?
Re: Object Constructors {} key with quotation/mix array & ke
@Coco
It's just convention. Using one object constructor to initialize a mix object with index-key and noraml-key.
Also, can change the index base from 1 to 0 (see a), or change it in the middle effect the auto index-key behind (see f).
Like in static/constant object variable, so don't need any extra initialize code.
Otherwise, we should use object() or {}, and specify every key, like {0:a,1:b,2:c,3:d,m:n}.
It's just convention. Using one object constructor to initialize a mix object with index-key and noraml-key.
Also, can change the index base from 1 to 0 (see a), or change it in the middle effect the auto index-key behind (see f).
Like in static/constant object variable, so don't need any extra initialize code.
Otherwise, we should use object() or {}, and specify every key, like {0:a,1:b,2:c,3:d,m:n}.
我为人人,人人为己?
Re: Object Constructors {} key with quotation/mix array & ke
Well, you can override object() to implement your custom constructor behavior:
The downside, you would need to re-implement the other built-in object functions when called using [/c].Syntax(), plus this functionality as well addr := &obj, obj := Object(addr)
Code: Select all
object(args*) {
return new RobertL_CustomObject(args*)
}
class RobertL_CustomObject
{
__New(args*) {
;// put your code here
}
}
Re: Object Constructors {} key with quotation/mix array & ke
@Coco
It's hard to determine the key is an index or normal-key from which orginal determined by : now from , as param*.
You mean pares string '0:"a","b","c",4:"e","f",m:n' to object with a function (don't need to override anything). Oh, also difficult to handle expression (variable).
I think it would be a big convention to expand the object constructor.
It's hard to determine the key is an index or normal-key from which orginal determined by : now from , as param*.
You mean pares string '0:"a","b","c",4:"e","f",m:n' to object with a function (don't need to override anything). Oh, also difficult to handle expression (variable).
I think it would be a big convention to expand the object constructor.
我为人人,人人为己?
Re: Object Constructors {} key with quotation/mix array & ke
1. As you've shown, the key can be a quoted literal string. So ask yourself, how do you include quote marks in a quoted literal string?
2. No.
2. No.
Re: Object Constructors {} key with quotation/mix array & ke
@lexikos
1. I found t:={'"a"':1} correct in V2.
2. The purpose is here at 3#. I think it's a bigconventionconvenience (although just for convention).
1. I found t:={'"a"':1} correct in V2.
2. The purpose is here at 3#. I think it's a big
Last edited by RobertL on 27 Aug 2014, 20:52, edited 3 times in total.
我为人人,人人为己?
Re: Object Constructors {} key with quotation/mix array & ke
2. And? The answer is still No.
I think you mean "convenience", not "convention".
I think you mean "convenience", not "convention".
Re: [Vetoed]Object Constructors {} key with quota/mix array&
Sorry, I overlooked the fact that this is in the Wish List forum. If the question was can it be done in the current version, the answer is as I said: No. It could be done in a future version, but I don't intend to do it. It generally wouldn't be very useful, since scripts tend not to mix the two, especially in object literals.
Re: [Vetoed]Object Constructors {} key with quota/mix array&
@lexikos
OK. I see, no problem.
I will use a function (Add an auto-count index/key) to do this, may be used in some occasional case.
OK. I see, no problem.
I will use a function (Add an auto-count index/key) to do this, may be used in some occasional case.
我为人人,人人为己?
Who is online
Users browsing this forum: No registered users and 35 guests