Questions tagged [default-parameters]

A default parameter is a function or method parameter that has a default value provided to it. If the user does not supply a value for this parameter, the default value will be used. If the user does supply a value for the default parameter, the user supplied value is used.

A default parameter is a function or method parameter that has a default value provided to it. If the user does not supply a value for this parameter, the default value will be used. If the user does supply a value for the default parameter, the user supplied value is used.

366 questions
0
votes
1 answer

Why is applying a Python decorator with and without parenthesis different?

I have a self-written class-based Python decorator. As far as I can see there is a difference, when I apply the decorator to a method in a class. Usually, decorators like @classmethod, @staticmethod, @property or @unique are applied without…
0
votes
2 answers

Keeping named and default parameters when assigning a function

When assigning a function using an unapplied method, it appears that named and default parameters are lost. Is there any way to avoid this? def foo(namedParam: String = "defaultValue") = namedParam*2 // scala> foo() // res8: String =…
Alfredo Gimenez
  • 2,174
  • 1
  • 14
  • 19
0
votes
2 answers

Default Parameters for method in c#

I have the following method signature where I want to give a default value to one of my parameters but I dont want to give any default value to the other parameter leadSourceStatus protected PromotionCatalogResponseRootObject…
Huma Ali
  • 1,759
  • 7
  • 40
  • 66
0
votes
0 answers

How to change a default parameter programatically?

The question is pretty much self contained. I have a function with some default parameters, for example def f(x=None): # some code... defined in a module. I want to be able to import this function in a script and depending an some values…
Julien
  • 13,986
  • 5
  • 29
  • 53
0
votes
4 answers

How to set default values for named function parameters simulated via object literals in JavaScript?

I'd like to use named parameters (simulated via object literals) in my JavaScript functions for ease of readability. The code I've written works fine when I explicitly pass my parameters, but I'm having trouble trying to set a default value, so that…
0
votes
2 answers

POST actions with same name and different [default] params wont fire from an Ajax call

Basically, I have these 2 actions: [HttpPost] [ActionName("ListarTodosGrupo")] public ActionResult ListAllFromGroup(string wildcard = "", int registries = 10) { // ... } [HttpPost] [ActionName("ListarTodosGrupo")] public ActionResult…
Yves Calaci
  • 1,019
  • 1
  • 11
  • 37
0
votes
1 answer

parameter with default object value

I have a class and function class A { A(int i = 0) { } } void f(A a = new A(10)) // ? default parameter value must be compiler-time constanct { } How to workaround it?
user1899020
  • 13,167
  • 21
  • 79
  • 154
0
votes
1 answer

C# params without an inline array cause an error "Named argument specifications must appear after all fixed arguments have been specified"

I have created a method called "tag" that returns an HtmlTag object and get params of type "HtmlTag" (See below). I'm trying to pass the params without an inline array but I get an error: "Named argument specifications must appear after all fixed…
Loves2Develop
  • 774
  • 1
  • 8
  • 29
0
votes
1 answer

Signature of the function with default parameters

def addition(a:Int, b:Int = 5) = a + b val k = addition _ k(2) //This does not work Also If I want to pass k as a parameter to another function what should be the signature of that function.
scout
  • 2,336
  • 4
  • 21
  • 22
0
votes
2 answers

Overloading a function that has default arguments

In C++, if I overload a function like the following void foo(int bar); void foo(int bar, float baz = 0); And then I call it foo(1); Which foo would be called?
0
votes
1 answer

How to use interface and default parameters together?

Code below: enum Type { digit=1, alpha=2, alnum=3 } enum Transform{uppercase=1,lowercase} interface Options { type: Type; length: number; min: number; max: number; uppercase: boolean; lowercase: boolean; transform:…
codelegant
  • 583
  • 2
  • 6
  • 19
0
votes
1 answer

Setting Javascript Function Parameters inside the function parenthesis

This is so simple I forgot how to do it. I've always passed variables to a function hence it's param's were pre-set, now I need to set the param's when declaring the function, but don't remember the setup. I'm looking for the working version of…
0
votes
3 answers

Can I always use `||` to assign default parameter values?

Optional Parameters I often have JavaScript functions with optional parameters. Instead of writing a long check like this: if(param === null || param === undefined){ param = {}; } I usually use the following syntax: function…
maja
  • 17,250
  • 17
  • 82
  • 125
0
votes
3 answers

AS3: EventListener callback overrides function's default parameters?

I discovered encountered something weird today. I have a function with a Boolean default parameter: function f(boolean:Boolean=false) { trace(boolean); } Calling it normally gives what you would expect: f(); //traces false But now if I make my…
0
votes
1 answer

Assigning to an optional reference parameter

Say we have define a function that takes a reference paramter which will contain an error message, but we don't always need the error message, so we allow that reference parameter to be omitted: function isSpider($bug, &$errorMsg = null) { …
Chris Middleton
  • 5,654
  • 5
  • 31
  • 68