Is it possible to skip an optional parameter and assign a value to the parameter after the missing one?
For example, I have a function:
public function Dialog(message:String,title:String="Note",dialogsize:int=99):void { }
I can easily call a function with a message and a header:
Dialog("HELLO","Intro");
Is there a way to skip the title and just go through the dialog? I tried but can't make it work:
Dialog("HELLO",,dialogsize);
Can I skip some optional parameters without using the (rest) parameter?
null, "defaulted", as3 - , :
null
Dialog("HELLO",null,dialogsize);
Edit
- , , ... ( , @www0z0k ) . , .
- :
public function Dialog(message:String,title:String=null,dialogsize:int=99):void { if(title===null) title = "Note"; }
, - :
public function Dialog(message:String, optionalArgs: Object):void{ var title: String = optionalArgs['title'] ? optionalArgs['title'] : 'default value'; var dialogsize: int = optionalArgs['dialogsize'] ? optionalArgs['dialogsize'] : 99; var smthElse: String = optionalArgs['smthElse'] ? optionalArgs['smthElse'] : 'another default val'; }
:Dialog('msg', {dialogsize: 250, smthElse: 'another value'});
Dialog('msg', {dialogsize: 250, smthElse: 'another value'});
value , :
// DialogVO.as package { public class DialogVO { public var message : String; public var title : String; public var size : int; } }
// Test.as public function createDialog(vo : DialogVO) : void { if(vo.title) // write code for title here if(vo.message) // write code for meassage here if(vo.size) // write code for size here }
// test your method var dialogData : DialogVO = new DialogVO(); dialogData.message = "This is the message"; dialogData.size = 92; createDialog(dialogData);
Source: https://habr.com/ru/post/1780151/More articles:The problem of connecting mysql and Java - javaHow to use partial templates with a map in StringTemplate? - stringtemplateResizing an image inside a container dynamically using jQuery - jqueryDatabase Modeling: Delivery Rules - databasePassing function pointers between modules - c ++REST uses only receiving and publishing - jsonWhat happened to this image cropper? - c #uninformative error using boost :: iterator_adaptor - c ++How to connect to a local host using JDBC? - javaHow to format tall graphics? - jqueryAll Articles