二、javascript函数参数的默认值 c语言中可以通过这样来设置默认参数: 代码如下: void foo(int a, int b = 1, bool c = false);
但是javascript却不能这样: newGame : function(a, b = 0) ie和chrome会报错,ff会直接忽略。 我们可以用arguments只读变量数组来实现: 代码如下: function newGame(){ var a = arguments[0] ? arguments[0] : 1; var b = arguments[1] ? arguments[1] : false; //函数内容 }