please explain the apply and call methods in javascript

Possible Duplicate: What is the difference between call and apply? What is the main difference between apply and call methods... I go through the web but unable to find the best solution.. Please help me friends... Every function in JavaScript receives two objects in addition to the default parameters. These are this and arguments . The value of this is determined by it's invocation p

请在javascript中解释应用和调用方法

可能重复: 通话和申请有什么区别? 应用程序和调用方法之间的主要区别是什么...我通过网络,但无法找到最佳解决方案..请帮助我的朋友... 除了缺省参数之外,JavaScript中的每个函数都会接收两个对象。 这是this和arguments 。 值this是由它的调用模式来确定。 apply或call可被用来调用一个函数,并为其提供一个默认的this对象。 这在许多情况下会非常有用。 例如, arguments是一个类似数组的对象,但并不是真正的A

Pass unknown number of parameters to JS function

This question already has an answer here: What is the difference between call and apply? 19 answers What you want is probably Function.prototype.apply() . Usage: var params = [param1, param2, param3]; functiona.apply(this, params); As others noted, functiona declaration may use arguments , eg: function functiona() { var param1 = this.arguments[0]; var param2 = this.arguments[1];

将未知数量的参数传递给JS函数

这个问题在这里已经有了答案: 通话和申请有什么区别? 19个答案 你想要的可能是Function.prototype.apply() 。 用法: var params = [param1, param2, param3]; functiona.apply(this, params); 正如其他人所指出的, functiona声明可以使用arguments ,例如: function functiona() { var param1 = this.arguments[0]; var param2 = this.arguments[1]; } 但它也可以使用任意数量的正常参数: function foo

Javascript Funky array mishap

function a() { var b = ["b"]; console.log(b); //console.log(b.slice()); b = b.push("bb"); } a(); In a "perfect" world you would think that the console.log would show ["b"] , but wildly enough it shows ["b", "bb"] even though "bb" isn't pushed on until afterwards. If you do console.log(b.slice()); Then you will get the desired resul

JavaScript时髦的数组事故

function a() { var b = ["b"]; console.log(b); //console.log(b.slice()); b = b.push("bb"); } a(); 在一个“完美”的世界中,你会认为console.log会显示["b"] ,但是非常足够显示["b", "bb"]即使之后“bb”没有被推入。 如果你做了console.log(b.slice()); 然后你会得到["b"]所需的结果。 这是为什么? 这种并发症背后的原因是什么? 我只是想更好地理解这一点,所以我

Does IE9 support console.log, and is it a real function?

In which circumstances is window.console.log defined in Internet Explorer 9? Even when window.console.log is defined, window.console.log.apply and window.console.log.call are undefined. Why is this? [Related question for IE8: What happened to console.log in IE8?.] In Internet Explorer 9 (and 8), the console object is only exposed when the developer tools are opened for a particular tab. I

IE9是否支持console.log,它是一个真正的功能?

在哪些情况下是在Internet Explorer 9中定义的window.console.log ? 即使window.console.log定义, window.console.log.apply和window.console.log.call是不确定的。 为什么是这样? [IE8的相关问题:IE8中console.log发生了什么变化?] 在Internet Explorer 9(和8)中, console对象仅在为特定选项卡打开开发人员工具时才公开。 如果您隐藏该选项卡的开发人员工具窗口,则console对象将保持显示您导航到的每个页面。

How can I combine two arrays into one array in javascript?

This question already has an answer here: How to append something to an array? 25 answers 使用Array.prototype.concat方法: var result = hora.concat(self.aEstados.estados); 使用Array.prototype.concat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat) var combined = hora.concat( self.aEstados.estados ); console.info( combined );

我怎样才能将两个数组组合成一个数组在JavaScript中?

这个问题在这里已经有了答案: 如何将某些东西附加到数组中? 25个答案 使用Array.prototype.concat方法: var result = hora.concat(self.aEstados.estados); 使用Array.prototype.concat (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat) var combined = hora.concat( self.aEstados.estados ); console.info( combined );

How to add new a new property to an object in an array?

This question already has an answer here: How to append something to an array? 25 answers Easiest way to append is either use: fruits[0]["taste"] = "good"; or: fruits[0].taste = "good"; I add an taste element to each object, and fill it with the value "good"+ index of the element . Here is a simple demo: var fruits = []; fruits[0] = {name:"apple", stock:"1box"}; fruits[1] =

如何将新的属性添加到数组中的对象?

这个问题在这里已经有了答案: 如何将某些东西附加到数组中? 25个答案 最简单的追加方式是使用: fruits[0]["taste"] = "good"; 要么: fruits[0].taste = "good"; 我为每个对象添加一个taste元素,并用元素的值"good"+ index of the element填充它。 这是一个简单的演示: var fruits = []; fruits[0] = {name:"apple", stock:"1box"}; fruits[1] = {name:"banana", stock:"2box"}; fruits[2] = {name:

Add elements to an Array

This question already has an answer here: How to append something to an array? 25 answers 您可以使用Array的push方法if (condition) { object.push({id: '#obj6'}, {id: '#obj7'}); }

将元素添加到数组

这个问题在这里已经有了答案: 如何将某些东西附加到数组中? 25个答案 您可以使用Array的push方法if (condition) { object.push({id: '#obj6'}, {id: '#obj7'}); }

How to add to an array in javascript?

This question already has an answer here: How to append something to an array? 25 answers First, the method to add element to array is called push , not add Second, when you do join on array, you get string, which doesn't have methods like push or add If you really want to do this, you need this code: var lootArray = [] lootArray.push("ramdom1"); lootArray = lootArray.join("<br

如何添加到JavaScript中的数组?

这个问题在这里已经有了答案: 如何将某些东西附加到数组中? 25个答案 首先,将元素添加到数组的方法称为push ,而不是add 其次,当你在数组上进行join时,你会得到字符串,它没有像push或add这样的方法 如果你真的想这样做,你需要下面的代码: var lootArray = [] lootArray.push("ramdom1"); lootArray = lootArray.join("<br>"); document.getElementById("text_loot").innerHTML = lootArray; 更换 lo

how add number to an array in javascript?

This question already has an answer here: How to append something to an array? 25 answers 在添加到字符串之前,您需要将字符串解析为一个整数: var dt = "12/02/2012"; var mm = de.split("/"); var year = parseInt(mm[2])+1;

如何将数字添加到JavaScript中的数组?

这个问题在这里已经有了答案: 如何将某些东西附加到数组中? 25个答案 在添加到字符串之前,您需要将字符串解析为一个整数: var dt = "12/02/2012"; var mm = de.split("/"); var year = parseInt(mm[2])+1;

Array of objects on a json

This question already has an answer here: How to append something to an array? 25 answers 只需将新项目推送至历史数组: this.disputa.historico.push({ fl_usuario: "", created_at: "", updated_at: "", created_by: null, updated_by: null, texto: "" }); 只需追加一个数组: this.disputa.historico.push({/* your object here*/}); You run i

json上的对象数组

这个问题在这里已经有了答案: 如何将某些东西附加到数组中? 25个答案 只需将新项目推送至历史数组: this.disputa.historico.push({ fl_usuario: "", created_at: "", updated_at: "", created_by: null, updated_by: null, texto: "" }); 只需追加一个数组: this.disputa.historico.push({/* your object here*/}); 你遇到错误 无法将属性'tex