草庐IT

pll_register_string

全部标签

javascript - 只是好奇如何继承 String 对象。 (原型(prototype))

我知道这是不受欢迎的,我只是在探索这个想法,就我的生活而言,似乎无法按照我想要的方式完成这项工作。这个例子应该解释所有:String.prototype.MyNS=function(){}String.prototype.MyNS.fooify=function(){returnthis+'foo!';}vartheString='Kung';alert(theString.MyNS.fooify());当然,这只是将函数定义附加到“foo”……添加this()是行不通的。我知道我在那里失去了背景,但无法弄清楚如何让原件开火并给我我想要的东西。 最佳答案

javascript - 谷歌图表 : is it possible to use Strings for the x axis?

所以我试着摆弄我的图表,发现整数/float/日期在x轴上工作得很好,但是当你输入一个字符串时,它就爆炸了。我正在尝试绘制a:Word/Count图表,但不幸的是我似乎无法将字符串放在x轴上。这在GoogleCharts中是允许的,还是严格意义上的int/floats/dates? 最佳答案 如下使用vAxis和hAxis属性google.visualization.ColumnChart(document.getElementById('visualization')).draw(data,{title:"YearlyCoffee

javascript - new String() 的行为不像对象那样的数组

varnice=newString("ASH");nice;//String{0:"A",1:"S",2:"H",length:3,[[PrimitiveValue]]:"ASH"}varreverseNice=Array.prototype.reverse.call(nice);reverseNice.toString();//"ASH"而我期望reverseNice是“HSA”。 最佳答案 不能改nice,试试看;nice[0]='f';nice[0];//"A"如果您想使用Array方法,请先将其转换为真正的Arrayvarr

JavaScript element.classList.add ("fa fa-hand-rock-o") 错误 : "String contains an invalid character"

我正在尝试添加一个类使用:document.getElementById("sp1").classList.add("fafa-hand-rock-o");但是显示错误:Stringcontainsaninvalidcharacter 最佳答案 fafa-hand-rock-o不能是单个类,因为类名不能有空格。这里我假设您正在尝试添加两个不同的类。使用classList.add()添加多个类时,将所有类指定为单独的逗号分隔字符串,如:.add("fa","fa-hand-rock-o")代码示例:document.getElemen

javascript - 为什么 String.prototype 里面的 'this' 指的是对象类型,而不是字符串类型?

我正在尝试扩展字符串以提供其自身的散列。我正在使用Node.js加密库。我这样扩展字符串:String.prototype.hashCode=function(){returngetHash(this);};我有一个看起来像这样的getHash函数:functiongetHash(testString){console.log("typeis"+typeof(testString));varcrypto=require('crypto');varhash=crypto.createHash("sha256");hash.update(testString);varresult=hash

javascript - 不能将 String.prototype.match 用作 Array.some 的函数吗?

这行不通:vars='^foo';console.log(['boot','foot'].some(s.match));UncaughtTypeError:String.prototype.matchcalledonnullorundefined但是这样做:vars='^foo';console.log(['boot','foot'].some(function(i){returni.match(s)}));这是为什么?我以某种方式想象String.prototype.match函数太“原始”之类的,但究竟是为什么呢?因为我没有使用ES2015,所以第二个版本看起来很冗长。有替代方案吗

javascript - 为什么我看到 javascript 数组是用 string.split() 创建的?

我在网上看到这样的代码vardays="MondayTuesdayWednesdayThursdayFridaySaturdaySunday".split("");为什么这样做而不是vardays=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];我不认为懒惰或无知与它有任何关系。这是jQuery1.4.2之外的props:"altKeyattrChangeattrNamebubblesbuttoncancelablecharCodeclientXclientYctrlKeycurrentT

javascript - 为什么 String.prototype 的方法可用于字符串文字?

这个问题出自another,它涉及console.dir与字符串文字的行为。特别是,请参阅关于myanswer的评论.众所周知,JavaScript中的String对象有很多方法。这些方法在String.prototype对象上定义。String.prototype.toUpperCase例如。因此,我们可以这样做:vars=newString("hello"),s2=s.toUpperCase();//toUpperCaseisamethodonString.prototype不过,我们也可以这样做:vars="hello",//sisastringliteral,notaninst

javascript - 逗号分隔值 : from strings to objects to list

我有3个变量,它们的字符串包含逗号分隔值(我不知道有多少),我想将它们合并到jQuery对象中。"name1,name2,name3,nameN""value1,value2,value3,valueN""id1,id2,id3,idN"到:varitem1={name:name1,value:value1,id:id1};varitem2={name:name2,value:value2,id:id2};varitem3={name:name3,value:value3,id:id3};varitemN={name:nameN,value:valueN,id:idN};然后对每个项目

javascript - jQuery.contents() 获取每个元素作为 HTML/STRING

我正在尝试使用jquery内容获取某些对象(包括文本)的HTML形式。这是我到目前为止得到的:HTMLtestfoobarjQuery$('#mydiv').contents().each(function(){console.log($(this).html());console.log($(this).prop("innerHTML"));console.log($(this).prop("outerHTML"));});有什么办法吗?我四处搜寻,但找不到任何东西。预先感谢您的回答! 最佳答案 如果您正在寻找包含包装元素的htm