jjzjj

argument

全部标签

javascript - 避免 React 中的内联函数 : How to bind functions with arguments?

我正在尝试关注no-bindReact使用他们推荐的ES6类模式的规则:classFooextendsReact.Component{constructor(){super();this._onClick=this._onClick.bind(this);}render(){return(Hello!);}_onClick(){//Dowhateveryoulike,referencing"this"asappropriate}}但是,当我需要将参数传递给_onClick时,需要更改什么?我试过类似的方法:import{someFunc}from'some/path';classFoo

javascript - 加密错误 : data and hash arguments required

我收到一个bcrypt错误,指出需要数据和哈希参数,引用我的routes.js文件中的第44行。据我所知,我正在传递该信息:bcrypt.compare的第一个参数是用户输入的密码,第二个是从数据库中检索到的散列密码。我做错了什么?bcrypt.compare(req.params.password,user.password,function...routes.js'usestrict'varexpress=require('express');varrouter=express.Router();varUser=require('../app/models/user');//pas

javascript - 为什么 push 显示 argument of type 'any[]' is not assignable to parameter of type 'never' 错误?

在这段代码中我得到了休闲错误:Argumentoftype'any[]'isnotassignabletoparameteroftype'never'varmarkers:[];this.Getlapoints(this.map.getCenter(),500000).then(data=>{for(varkeyindata){Leaflet.marker(data[key].location,//{icon:greenIcon}).addTo(this.map).bindPopup(data[key].caption);//markers.push(data[key].locatio

Javascript arguments.sort() 抛出错误 sort is not a function

只是想知道为什么我在使用以下简单的JavaScript函数时会出错functionhighest(){returnarguments.sort(function(a,b){returnb-a;});}highest(1,1,2,3);错误消息:TypeError:arguments.sort不是函数。我很困惑,因为它是一个数组(我认为)。请帮助并解释原因。非常感谢 最佳答案 因为arguments没有sort方法。请注意arguments不是Array对象,它是一个类似数组的Argumentsobject.但是,您可以使用Array

javascript - JS : functions arguments default values

在某些语言中,您可以为函数的参数设置默认值:functionFoo(arg1=50,arg2='default'){//...}如何在JavaScript中做到这一点? 最佳答案 在JavaScript中,任何未设置的值都被赋予值undefined。这意味着如果你想为一个函数设置默认值,你的第一行需要检查这些值是否未定义:functionFoo(arg1,arg2){if(typeof(arg1)==="undefined"){arg1=50;}if(typeof(arg2)==="undefined"){arg2="default

Javascript for..in 遍历参数 ie.for(arg in arguments) 在 IE8 中不起作用,但在 Chrome 8 中有效

我遇到了这种奇怪的情况,其中foreach之类的javascript构造在IE中不起作用,但在FF中有效。不是所有的for..in只是这个特殊的函数不起作用。我会发布代码。在IE8中测试。还使用XHTMLDTD进行了测试。Test更新我发布了一个错误的问题,它在FireFox中有效但在IE8中无效,这是错误的。它在FireFox中也不起作用。实际上我从帖子JavaScriptequivalenttoprintf/string.format得到了这段代码. 最佳答案 首先,虽然arguments函数中可用的对象不是数组,它足够“类似数

javascript - arguments.callee.toString() 和 arguments.callee.name 不返回函数名

我正在尝试获取当前正在运行的函数的名称。根据我的阅读,这应该可以使用:(arguments.callee.toString()).match(/function\s+(\[^\s\(]+)/)但是,当我在Firefox和Safari(Mac上的最新版本)中运行时,不会返回名称。console.log(arguments.callee)返回函数的源,但不返回分配的名称。arguments.callee.name返回空字符串。我的示例代码如下:vartestobj={testfunc:function(){console.log((arguments.callee.toString()).

javascript - 在严格模式下复制 arguments.callee

我是第一次在严格模式下工作,你知道吗,这也是多年来第一次能够使用非严格模式的属性。我的questionhere概述了我遇到的确切问题,但如果我仍然可以访问arguments.callee,我已经制定的解决方案可以适用于更具可扩展性的东西。在不命名函数的情况下,在严格模式下是否有任何方法可以获得对我当前范围内的函数的引用? 最佳答案 WithoutnamingthefunctionisthereanywayinstrictmodethatIcangetareferencetothefunctionwhosescopeI'mcurren

javascript - 鉴于 "arguments"不是真正的数组,为什么 Array.prototype.slice.call(arguments) 有效,而 Array.prototype.slice.call(someobject) 无效?

如果arguments只是一个具有length属性的对象,那么为什么它的行为似乎不同于其他非数组对象,例如Array.prototype.slice。例如,下面的代码首先提示“undefined”,然后提示“foo”。为什么这些不同?(function(a){varmyobj={0:"foo"};varmyobjarray=Array.prototype.slice.call(myobj);varargumentsarray=Array.prototype.slice.call(arguments);alert(myobjarray.shift());alert(argumentsar

javascript - 未捕获的 SweetAlert : Unexpected 2nd argument?

我有sweetalert的问题,我想在按钮点击时显示确认框警报,但它不起作用这是我的JS代码:$(document).ready(function(){$('[data-confirm]').on('click',function(e){e.preventDefault();//canceldefaultaction//Recuperatehrefvaluevarhref=$(this).attr('href');varmessage=$(this).data('confirm');//popupswal({title:"Areyousure??",text:message,type: