argument-passing

How to check if an argument is an object (and not an array) in JavaScript

試著忘記壹切 提交于 2019-12-02 00:53:40
After testing out instasnceof I found that it will return true if the argument is an array or an object literal. function test(options){ if(options instanceof Object){alert('yes')}//this will alert for both arrays and object literals } test({x:11})// alerts test([11])// alerts as well but I do not want it to Is there a way to test if the argument "options" is an object literal? P.S. I am creating a module that will allow the user to access its configuration options, and I want to test if the argument is only an object literal or not? is there a way to test if the argument "options" is an

splat over JavaScript object (with new)?

烂漫一生 提交于 2019-12-01 20:42:26
问题 How do I splat across objects without using ECMA6 features? Attempt function can(arg0, arg1) { return arg0 + arg1; } function foo(bar, haz) { this.bar = bar; this.haz = haz; } myArgs = [1,2]; With can I can just do: can.apply(this, myArgs); When trying with foo : new foo.apply(this, myArgs); I get this error (because I'm calling new ): TypeError: function apply() { [native code] } is not a constructor 回答1: Using Object.create function foo(bar, haz) { this.bar = bar; this.haz = haz; } x =

Process.Start - Pass html code to exe as argument

限于喜欢 提交于 2019-12-01 20:04:13
I am using the code below to start a executable file from a windows service and I need to pass html code (stored in a variable) as an argument. I am escaping with double quotes but this is not working. What do I need to do in order to pass this correctly? Thanks in advance for any guidance that is offered. Inside the service: Process.Start(@"E:\Program Files\MyApp.exe", dr["rec"].ToString() + " \"" + subject + "\" \"" + htmlVar); and then within MyApp.exe: static void Main(string[] args) { Program MyProg = new Program(); MyProg.MyMeth(args[0].ToString(), args[1].ToString(), args[2].ToString())

splat over JavaScript object (with new)?

亡梦爱人 提交于 2019-12-01 19:50:46
How do I splat across objects without using ECMA6 features ? Attempt function can(arg0, arg1) { return arg0 + arg1; } function foo(bar, haz) { this.bar = bar; this.haz = haz; } myArgs = [1,2]; With can I can just do: can.apply(this, myArgs); When trying with foo : new foo.apply(this, myArgs); I get this error (because I'm calling new ): TypeError: function apply() { [native code] } is not a constructor Using Object.create function foo(bar, haz) { this.bar = bar; this.haz = haz; } x = Object.create(foo.prototype); myArgs = [5,6]; foo.apply(x, myArgs); console.log(x.bar); Ven Using Object.create

PowerShell Splatting the Argumentlist on Invoke-Command

和自甴很熟 提交于 2019-12-01 18:14:53
How is it possible to use the parameters collected in a hash table for use with ArgumentList on Invoke-Command ? $CopyParams = @{ Source = 'E:\DEPARTMENTS\CBR\SHARE\Target' Destination = 'E:\DEPARTMENTS\CBR\SHARE\Target 2' Structure = 'yyyy-MM-dd' } Invoke-Command -Credential $Cred -ComputerName 'SERVER' -ScriptBlock ${Function:Copy-FilesHC} -ArgumentList @CopyParams Whatever I try, it's always complaining about the 'Source': Cannot validate argument on parameter 'Source'. The "Test-Path $_" validation script for the argument with value "System.Collections.Hashtable" did not return true.

PowerShell Splatting the Argumentlist on Invoke-Command

陌路散爱 提交于 2019-12-01 17:52:17
问题 How is it possible to use the parameters collected in a hash table for use with ArgumentList on Invoke-Command ? $CopyParams = @{ Source = 'E:\DEPARTMENTS\CBR\SHARE\Target' Destination = 'E:\DEPARTMENTS\CBR\SHARE\Target 2' Structure = 'yyyy-MM-dd' } Invoke-Command -Credential $Cred -ComputerName 'SERVER' -ScriptBlock ${Function:Copy-FilesHC} -ArgumentList @CopyParams Whatever I try, it's always complaining about the 'Source': Cannot validate argument on parameter 'Source'. The "Test-Path $_"

How many ways are there to pass char array to function in C?

不羁岁月 提交于 2019-12-01 09:56:22
foo(char *s) foo(char *s[ ]) foo(char s[ ]) What is the difference in all these ? Is there any way in which I will be able to modify the elements of the array which is passed as argument, just as we pass int or float using & and value of actual arguments gets modified? It is not possible in C to pass an array by value. Each working solution that you listed (which unfortunately excludes #2) will not only let you, but force you to modify the original array. Because of argument decay, foo(char* s) and foo(char s[]) are exactly equivalent to one another. In both cases, you pass the array with its

Performance when passing huge list as argument in recursive function?

早过忘川 提交于 2019-12-01 09:14:13
I am using Python and I have a recursive function that takes a huge list as one of the arguments: # Current implementation def MyFunction(arg1, arg2, my_huge_list) ... ... MyFunction(new_arg1, new_arg2, my_huge_list) As you can see above, MyFunction is called recursively using the same list my_huge_list ; this doesn't change, unlike the other arguments. And, again, this list is huge. A friend of mine suggested that I could treat my_huge_list as a global variable to improve the performance, as otherwise this huge list may be copied over and over in every iteration. # Friend's suggestion

How many ways are there to pass char array to function in C?

折月煮酒 提交于 2019-12-01 07:30:11
问题 foo(char *s) foo(char *s[ ]) foo(char s[ ]) What is the difference in all these ? Is there any way in which I will be able to modify the elements of the array which is passed as argument, just as we pass int or float using & and value of actual arguments gets modified? 回答1: It is not possible in C to pass an array by value. Each working solution that you listed (which unfortunately excludes #2) will not only let you, but force you to modify the original array. Because of argument decay, foo

Does Fortran intent(inout) pass a copy of the value, or pointer/reference to RAM address?

ぐ巨炮叔叔 提交于 2019-12-01 06:32:23
As title states I wish to know does Fortran intent(inout) pass a copy of the value, or a pointer/reference to RAM address? The reason I need to know this is I need to pass a (relatively) big data matrix. If it creates a local copy that would cause me problems. Thank you! Fortran does not specify details of how function and subroutine arguments are passed, but it does require that if a procedure modifies an intent(out) or intent(inout) argument then the changes will be visible to the caller after the procedure returns. It is common for compilers to implement this requirement by passing