草庐IT

String-argument

全部标签

javascript - TypeError [ERR_INVALID_ARG_TYPE] : The "original" argument must be of type Function. 接收类型未定义

在下面的代码中,我得到了这个错误:TypeError[ERR_INVALID_ARG_TYPE]:The"original"argumentmustbeoftypeFunction.Receivedtypeundefinedconstsqlite3=require('sqlite3').verbose();constutil=require('util');asyncfunctiongetDB(){returnnewPromise(function(resolve,reject){letdb=newsqlite3.Database('./project.db',(err)=>{if(e

javascript - 不能使用 String#trim 作为 Array#map 的回调

出于某种原因,我不能使用String.prototype.trim.call作为数组方法的回调,例如map或filter.在这种情况下,两个函数工作相同:functiontrim(string){returnstring.trim();}varstring='A';trim(string);//'A'String.prototype.trim.call(string);//'A'但是,当我尝试将它们作为数组方法的回调传递时,第二个失败了:vararray=['A','B','C'];array.map(trim);//['A','B','C'];array.map(String.pro

c# - 在 C# 中等效的 Javascript atob(string)

我这样做了:byte[]data=Convert.FromBase64String(str);stringdecodedString=Encoding.UTF8.GetString(data);Console.WriteLine(decodedString);但得到了未处理的异常:System.FormatException:Base-64字符数组或字符串的长度无效。在javascript中使用atob(str)给我正确的解码字符串。javascript控制台:atob("eyJpc3MiOiJodHRwczovL2lkZW50aXR5LXN0YWdpbmcuYXNjZW5kLnh5e

javascript - Babel/Karma/Chai 给出 TypeError : 'caller' , 'callee' 和 'arguments' properties may not be accessed on strict mode functions

我无法弄清楚为什么这个测试没有通过。varexpect=require('chai').expect;describe('HelloComponent',function(){it('passesaquitesimpletest',function(){expect(1+4).to.equal(5);});});产生这个错误:DEBUG[web-server]:serving:/Users/ivan/dev/react-starter/node_modules/karma/static/context.htmlDEBUG[web-server]:serving(cached):/Use

javascript - 获取行数据失败,错误 Cannot create property 'guid' on string

我正在使用jquery数据表。当我尝试检索行数据时,出现了Cannotcreateproperty'guid'onstring错误。http://jsfiddle.net/rqx14xepvaremployersTable=$('#employersTable').DataTable();$('#add').click(function(){addRow($('.username').val(),$('.phone').val());});$('body').on('click','#employersTabletr',retrieveRow(this));functionaddRow

javascript - 我无法准确理解 JavaScript 的方法 string.match(regexp) 的 g 标志是如何工作的

在《JavaScript:TheGoodParts》一书中解释了方法string.match(regexp)如下:Thematchmethodmatchesastringandaregularexpression.Howitdoesthisdependsonthegflag.Ifthereisnogflag,thentheresultofcallingstring.match(regexp)isthesameascallingregexp.exec(string).However,iftheregexphasthegflag,thenitproducesanarrayofallthem

javascript - 将 'arguments' 传递给 'apply()' 是否安全

假设我有以下代码(完全没用,我知道)functionadd(a,b,c,d){alert(a+b+c+d);}functionproxy(){add.apply(window,arguments);}proxy(1,2,3,4);基本上,我们知道apply需要一个数组作为第二个参数,但我们也知道arguments不是一个正确的数组。代码按预期工作,所以可以肯定地说我可以将任何类似数组的对象作为apply()中的第二个参数传递吗?以下内容也可以使用(至少在Chrome中):functionproxy(){add.apply(window,{0:arguments[0],1:argumen

javascript - 替代 arguments.callee

我有一个EventListener可以监听整个文档并记录击键,但我想在满足某些条件时删除此监听器。以下是我的代码片段:document.addEventListener('keyup',function(e){varletter_entered=String.fromCharCode(e.keyCode).toLowerCase();player.makeGuess(letter_entered);if(player.win_status===true||player.lose_status===true){document.removeEventListener('keyup',ar

javascript - JavaScript 中 String 对象的属性值

据我了解,每个字符串都是Javascript中的一个对象。尽管如此,它仍然“不起作用”,正如我所期望的那样:vara="abc";//herewegetanewstringobjecta.b=123;//Iseemtodeclareaproperty"b"ofthatobjectalert(a.b);//alerts"undefined"但是,如果我尝试以“错误的方式”定义字符串,一切都会按预期进行vara=newString("abc");//a.b=123;alert(a.b);//alerts"123"为什么会这样? 最佳答案

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