nodejs pass parameter after parameter - node.js

I know that the title looks crazy
but here is the problem
i have a function with 2 parameter both have default value
function a(author="unknown" message="my message"){
...
}
i can access it using a("john", "hello")
but what if i need to change only the 2nd parameter?
a("","hello")
if i set the first param to "" it change the default
so i need to do?
i want is a(default,message="new message")

An alternative way to achieve this is if you can modify the function to accept an object then you can choose which parameters to pass in.
function a({ author="unknown", message="my message" } = {}){
...
}
then to call it
a({ message: "new message" }

Put simply, no, there is no way in js to get parameters by name, only by order.
You can always consult the docs for that information here.

You should call your function in the below manner.
eg.
a(undefined, "new message")
This will take default value of author and take message parameter.
This is answered properly in one of the question. Check it here

Related

defined function call returns name not defined error

I have defined a following function:
def create_table(table,L):
table={'BBGTicker':L}
table=pd.DataFrame(table)
return table
trying to execute for example:
c=create_table(c,put_options_create)
where put_options_create is a list returns following error:
name 'c' is not defined.
If I was to write:
c={'BBGTicker':put_options_create}
c=pd.DataFrame(c)
this would work and give me a table.
What is wrong with the above function?
The first parameter of create_table is useless. table, the parameter, is immediately overwritten by table={'BBGTicker':L}, so there's no point in having that parameter.
Just change the function to:
def create_table(L):
table={'BBGTicker':L}
table=pd.DataFrame(table)
return table
and then call it as
c=create_table(put_options_create)
To answer why this is the case though: the variables between the () during a function call must already exist. If you haven't already assigned c a value, create_table(c,put_options_create) doesn't make sense. You only supply data there that you're giving a function. You don't specify in the parameter list data that you expect to get back*.
* It is possible to "return" data via parameters via mutation of objects, but that isn't what you're attempting to do here.

How could I return link to object property and not a value in Python3?

Thank you for taking your time.
Here is my code:
right_field_return(player, player.what_to_edit) = message
This call raise SyntaxError: can't assign to function call and I do understand it, but...
What does right_field_return does?
It is return objects field like this:
return player.current_mission.name
What I want to do?
I want to assign message value to player.current_mission.name
What do I get now?
Well, all I can do now is to return a VALUE from right_field_return, and I want to return a link to property player.current_mission.name - is there any way I can do it this way? Or maybe you can help me out and point in the other direction?
thank you
You should define a setter method in your class that takes message as an argument and sets new value to player.current_mission

Google Sheets Script Parameter for e.g. Button

Is it possible to pass parameters on a signed script?
I have a spreadsheet and made a couple of buttons signing functions to each.
Sample function:
function foo(){
return "bar";
}
Calling this function on a cell
=foo()
returns me bar, signing this function to a button
foo
returns me nothing but of course it works. I mean the script cant return a string to an image (whats actually my button). Anyways...
Sample function with parameter:
function foo(bar){
return bar;
}
calling the script in a cell
=foo('hello world')
returns me hello world as expacted
Signing this to my button
foo('hello world')
causes an error because the button cant find the script. He's searching for a function name foo('hello world') but (...) has non to do with the function.
So how can I pass params when signing script?
At the moment I have 26 functions (all the same, only 1 param changes) to solve this. But with passing a parameter I could do all this with 2 functions instead of 26.
You can't pass parameters when using a custom function via assigning it to a drawable image. It only works when the custom function is called from a cell.
Possible workarounds is to store your parameters on certain sheets and cells then retrieve them via
getRange() and getDisplayedValue().
Other possible workarounds are posted in a Google product help forum which can be found here
I found the best option to create separate helper methods for each individual button, which then pass the correct parameter to the generic method.
In the below example you would bind to the buttons the city specific method, for example for "Helsinki" button "updateAvailabilityInfoHelsinki".
function updateAvailabilityInfoHelsinki() {
updateAvailabilityInfo("Helsinki");
}
function updateAvailabilityInfoPorvoo() {
updateAvailabilityInfo("Porvoo");
}
function updateAvailabilityInfo(citySheet) {
// Do something with citySheet parameter
}

How to get the name of the current layout?

symfony getLayout does not seem to work when layout is set via view.yml. Is there anyway to get this within the controller's action class method
I recently needed this. You can do it but you just need to return the entire view.yml contents as an array:
$view_array = sfViewConfigHandler::getConfiguration(array(sfConfig::get('sf_app_config_dir').'/‌​view.yml'));
Just adjust the relative path from sf_app_config_dir (or use another marker) to get what you need.
It's not a trivial task. The view.yml, is not in the "scope" of the action.
Maybe, you can use setLayout in your action rather then in view.yml.
if you can't, for some reasons... you can try this method to reach datas in view.yml:
Is it possible to get a value from view.yml in an action
Execute the following code in the action. It works for both cases, layout set in the action or in the view.yml.
$controller = $this->getContext()->getController();
$view = $controller->getView($this->getModuleName(), $this->getActionName(), 'Success'); // viewName == 'Success' (default)
$layout_name = $view->getDecoratorTemplate(); // e.g expected: layout.php
Let us know if it works for you.

How to use the GetChanges method of SiteData WebService

Can anyone elaborate on the parameter values to be supplied for GetChanges method of SiteData Web Service?
Basically I am not able to understand what value should we supply for startChangeID and EndChangeID and from where can we get these values?
Any help on this would be greatly appreciated.
Thanks.
Try calling GetContent first with
string result = mysiteDataServiceInstance.GetContent(SiteDataService.ObjectType.ContentDatabase,
myContentDbGuid.ToString(), "", "", false, false, ref lastChangeID);
Where lastChangeID is an empty string. This should give back results like
<ContentDatabase><Metadata ChangeId="1;0;146b129e-4f56-4701-ada2-b370744f2ca3;633896405160170000;168811216" ID="{146b129e-4f56-4701-ada2-b370744f2ca3}" /></ContentDatabase>
Where 146b129e-4f56-4701-ada2-b370744f2ca3 is the guid of my ContentDb
The ChangeId mentioned here can be used in place of the lastChangeId and currentChangeId.
My results appeared like
<SPContentDatabase Change="Unchanged" ItemCount="0">
<ContentDatabase><Metadata ChangeId="1;0;146b129e-4f56-4701-ada2-b370744f2ca3;633896953296070000;30349699" ID="{146b129e-4f56-4701-ada2-b370744f2ca3}" /></ContentDatabase></SPContentDatabase>
The process is exactly the same when using SiteDataService.ObjectType.Site

Resources