Hello again!
Do you…
function myfunc(config:Object){
if(!config.url) config.url = "http://www.google.com/";
if(!config.target) config.target = "_blank";
}
…and so on for each parameter?
Am I missing a simpler way to do this?
Regards!
Hello again!
Do you…
function myfunc(config:Object){
if(!config.url) config.url = "http://www.google.com/";
if(!config.target) config.target = "_blank";
}
…and so on for each parameter?
Am I missing a simpler way to do this?
Regards!
Well, if you use this kind of Object alot one way you could do this is to create a class for it. It could be a simple small one that has all of the properties you need and does all the value defaulting inside the class. That’d be the way I would do this anyway.
Of course if you only do this in one place a class might not be worth it. In that case, no I don’t know any other way to default the parameters of an object.
Thanks!
The class approach is a good idea. Not for this time, but I’ll use that for sure.
may the force be with you
Slightly shorter:
var o:Object = new Object();
o.prop ||= 'hi';
o.prop ||= 'hey';
trace(o.prop); // hi
[QUOTE=Krilnon;2346088]Slightly shorter:
var o:Object = new Object();
o.prop ||= 'hi';
o.prop ||= 'hey';
trace(o.prop); // hi
[/QUOTE]
Hmmm looks interesting, never thought of using the OR operator this way.
How does it work exactly?
:: Copyright KIRUPA 2024 //--