argument-passing

How to pass an argument to a PowerShell script?

…衆ロ難τιáo~ 提交于 2019-11-26 16:57:17
There's a PowerShell script named itunesForward.ps1 that makes the iTunes fast forward 30 seconds: $iTunes = New-Object -ComObject iTunes.Application if ($iTunes.playerstate -eq 1) { $iTunes.PlayerPosition = $iTunes.PlayerPosition + 30 } It is executed with prompt line command: powershell.exe itunesForward.ps1 Is it possible to pass an argument from the command line and have it applied in the script instead of hardcoded 30 seconds value? Ocaso Protal Tested as working: param([Int32]$step=30) #Must be the first statement in your script $iTunes = New-Object -ComObject iTunes.Application if (

Passing an instance method as argument in PHP

一世执手 提交于 2019-11-26 16:49:06
问题 I would like to create a Listener class class Listener { var $listeners = array(); public function add(callable $function) { $this->listeners[] = $function; } public function fire() { foreach($this->listeners as $function) { call_user_func($function); } } } class Foo { public function __construct($listener) { $listener->add($this->bar); } public function bar() { echo 'bar'; } } $listener = new Listener(); $foo = new Foo($listener); But this code fails with this error: Notice: Undefined

Trouble passing on an argument to function within own function

依然范特西╮ 提交于 2019-11-26 16:48:27
问题 I am writing a function in which I want to pass some arguments to the crrstep-function ('crrstep' package), but I encountered a problem: somehow the argument 'event' in my function is not recognized when I enter it in crrstep. I guess that crrstep looks in a different environment than the one I want it to look, but even after hours of searching for solutions on the web, I cannot seem to figure out how to solve this (I am quite inexperienced in programming..). Any help would be greatly

Is there a way to use two '…' statements in a function in R?

不羁的心 提交于 2019-11-26 15:52:44
I want to write a function that calls both plot() and legend() and it would be ideal if the user could specify a number of additional arguments that are then passed through to either plot() or legend() . I know I can achieve this for one of the two functions using ... : foo.plot <- function(x,y,...) { plot(x,y,...) legend("bottomleft", "bar", pch=1) } foo.plot(1,1, xaxt = "n") This passes xaxt = "n" to plot. But is there a way for example to pass e.g. title = "legend" to the legend() call without prespecifying the arguments in the function header? Update from the accepted answer: I thought

How to pass event as argument to an inline event handler in JavaScript?

谁说我不能喝 提交于 2019-11-26 15:12:32
// this e works document.getElementById("p").oncontextmenu = function(e) { e = e || window.event; var target = e.target || e.srcElement; console.log(target); }; // this e is undefined function doSomething(e) { e = e || window.event; var target = e.target || e.srcElement; console.log(target); } <p id="p" onclick="doSomething(e)"> <a href="#">foo</a> <span>bar</span> </p> There are some similar questions have been asked. But in my code, I'm trying to get child elements who's been clicked, like a or span . So what is the correct way to pass event as an argument to event handler, or how to get

Argparse - do not catch positional arguments with `nargs`.

时光毁灭记忆、已成空白 提交于 2019-11-26 14:35:54
问题 I am trying to write a function wo which you can parse a variable amount of arguments via argparse - I know I can do this via nargs="+" . Sadly, the way argparse help works (and the way people generally write arguments in the CLI) puts the positional arguments last. This leads to my positional argument being caught as part of the optional arguments. #!/usr/bin/python import argparse parser = argparse.ArgumentParser() parser.add_argument("positional", help="my positional arg", type=int) parser

Passing parameters dynamically to variadic functions

旧巷老猫 提交于 2019-11-26 11:31:55
问题 I was wondering if there was any way to pass parameters dynamically to variadic functions. i.e. If I have a function int some_function (int a, int b, ...){/*blah*/} and I am accepting a bunch of values from the user, I want some way of passing those values into the function: some_function (a,b, val1,val2,...,valn) I don\'t want to write different versions of all these functions, but I suspect there is no other option? 回答1: Variadic functions use a calling convention where the caller is

How to pass an argument to a PowerShell script?

浪尽此生 提交于 2019-11-26 04:58:24
问题 There\'s a PowerShell script named itunesForward.ps1 that makes the iTunes fast forward 30 seconds: $iTunes = New-Object -ComObject iTunes.Application if ($iTunes.playerstate -eq 1) { $iTunes.PlayerPosition = $iTunes.PlayerPosition + 30 } It is executed with prompt line command: powershell.exe itunesForward.ps1 Is it possible to pass an argument from the command line and have it applied in the script instead of hardcoded 30 seconds value? 回答1: Tested as working: param([Int32]$step=30) #Must

How to pass event as argument to an inline event handler in JavaScript?

六月ゝ 毕业季﹏ 提交于 2019-11-26 04:12:47
问题 // this e works document.getElementById(\"p\").oncontextmenu = function(e) { e = e || window.event; var target = e.target || e.srcElement; console.log(target); }; // this e is undefined function doSomething(e) { e = e || window.event; var target = e.target || e.srcElement; console.log(target); } <p id=\"p\" onclick=\"doSomething(e)\"> <a href=\"#\">foo</a> <span>bar</span> </p> There are some similar questions have been asked. But in my code, I\'m trying to get child elements who\'s been

JavaScript variable number of arguments to function

半城伤御伤魂 提交于 2019-11-25 22:01:11
问题 Is there a way to allow \"unlimited\" vars for a function in JavaScript? Example: load(var1, var2, var3, var4, var5, etc...) load(var1) 回答1: Sure, just use the arguments object. function foo() { for (var i = 0; i < arguments.length; i++) { console.log(arguments[i]); } } 回答2: In (most) recent browsers, you can accept variable number of arguments with this syntax: function my_log(...args) { // args is an Array console.log(args); // You can pass this array as parameters to another function