标签: arguments

如何在JavaScript中将"arguments"对象转换为数组?

argumentsJavaScript中的对象是一个奇怪的疣 - 它在大多数情况下就像一个数组,但它实际上并不是一个数组对象.因为它是真正的完全是另一回事,它没有从有用的功能Array.prototype类似forEach,sort,filter,和map.

使用简单的for循环从arguments对象构造一个新数组非常容易.例如,此函数对其参数进行排序:

function sortArgs() {
    var args = [];
    for (var i = 0; i < arguments.length; i++)
        args[i] = arguments[i];
    return args.sort();
}
Run Code Online (Sandbox Code Playgroud)

但是,这是一个相当可怜的事情,只需要访问非常有用的JavaScript数组函数.是否有使用标准库的内置方法?

javascript arrays sorting arguments variadic-functions

424
推荐指数
8
解决办法
18万
查看次数

如何将unique_ptr参数传递给构造函数或函数?

我是新手在C++ 11中移动语义,我不太清楚如何处理unique_ptr构造函数或函数中的参数.考虑这个引用自身的类:

#include <memory>

class Base
{
  public:

    typedef unique_ptr<Base> UPtr;

    Base(){}
    Base(Base::UPtr n):next(std::move(n)){}

    virtual ~Base(){}

    void setNext(Base::UPtr n)
    {
      next = std::move(n);
    }

  protected :

    Base::UPtr next;

};
Run Code Online (Sandbox Code Playgroud)

这是我应该如何编写unique_ptr参数的函数?

我需要std::move在调用代码中使用吗?

Base::UPtr b1;
Base::UPtr b2(new Base());

b1->setNext(b2); //should I write b1->setNext(std::move(b2)); instead?
Run Code Online (Sandbox Code Playgroud)

c++ arguments unique-ptr c++11

377
推荐指数
5
解决办法
15万
查看次数

如何在javadoc中添加对方法参数的引用?

有没有办法从方法文档主体添加一个或多个方法参数的引用?就像是:

/**
 * When {@paramref a} is null, we rely on b for the discombobulation.
 *
 * @param a this is one of the parameters
 * @param b another param
 */
void foo(String a, int b)
{...}
Run Code Online (Sandbox Code Playgroud)

java arguments javadoc

303
推荐指数
4
解决办法
11万
查看次数

在Python中打印多个参数

这只是我的代码片段:

print("Total score for %s is %s  ", name, score)
Run Code Online (Sandbox Code Playgroud)

但我希望它打印出来:

"(姓名)总分为(得分)"

where name是列表中的变量,score是一个整数.这是Python 3.3,如果这有帮助的话.

python printing arguments python-3.x

283
推荐指数
10
解决办法
84万
查看次数

正常参数与关键字参数

"关键字参数"与常规参数有何不同?不能传递所有参数name=value而不是使用位置语法?

python arguments keyword optional-parameters named-parameters

271
推荐指数
8
解决办法
23万
查看次数

将最后一个参数传递给shell脚本

$1是第一个论点.
$@就是他们所有人.

如何找到传递给shell脚本的最后一个参数?

shell arguments

260
推荐指数
13
解决办法
12万
查看次数

C默认参数

有没有办法在C中为函数指定默认参数?

c arguments default-parameters

258
推荐指数
14
解决办法
19万
查看次数

jQuery将更多参数传递给回调

有没有办法将更多数据传递给jQuery中的回调函数?

我有两个函数,我希望回调$.post,例如,传递AJAX调用的结果数据,以及一些自定义参数

function clicked() {
    var myDiv = $("#my-div");
    // ERROR: Says data not defined
    $.post("someurl.php",someData,doSomething(data, myDiv),"json"); 
    // ERROR: Would pass in myDiv as curData (wrong)
    $.post("someurl.php",someData,doSomething(data, myDiv),"json"); 
}

function doSomething(curData, curDiv) {

}
Run Code Online (Sandbox Code Playgroud)

我希望能够将自己的参数传递给回调,以及从AJAX调用返回的结果.

javascript jquery arguments function callback

252
推荐指数
6
解决办法
20万
查看次数

C++或C中foo(void)和foo()之间有区别吗?

考虑这两个函数定义:

void foo() { }

void foo(void) { }
Run Code Online (Sandbox Code Playgroud)

这两者有什么区别吗?如果没有,为什么void那里的论点?美学原因?

c c++ arguments

243
推荐指数
3
解决办法
7万
查看次数

将数组转换为函数参数列表

是否可以将JavaScript中的数组转换为函数参数序列?例:

run({ "render": [ 10, 20, 200, 200 ] });

function run(calls) {
  var app = .... // app is retrieved from storage
  for (func in calls) {
    // What should happen in the next line?
    var args = ....(calls[func]);
    app[func](args);  // This is equivalent to app.render(10, 20, 200, 200);
  }
}
Run Code Online (Sandbox Code Playgroud)

javascript arrays arguments

234
推荐指数
4
解决办法
15万
查看次数