草庐IT

no-prototype-builtins

全部标签

javascript - 使用 .no-js 类检测 js

我一直使用在上有一个.no-js类的方法。标签,然后使用modernizr剥离标签并将其替换为js(如果在用户浏览器中启用了JavaScript)。基本上,我已经构建了一个CSS3移动和桌面导航。如果有CSS转换等(使用modernizr检查)以及是否有js或no-js,我有改变其行为的样式。问题是,在JavaScript有时间加载并将类更改为js之前,我看到了非js版本。(因为默认类是no-js)我想不通的是如何找到解决这个问题的办法。如果我将js特定代码作为主类,然后指定另一个带有前缀.no-js的代码,即使启用了js,它也会闪烁no-js。如果我切换它,它会做同样的事情.....

javascript - 原型(prototype)复制 vs Object.create() vs new

我在使用继承时注意到可以通过三种方式获得相同的结果。有什么区别?functionAnimal(){}Animal.prototype.doThat=function(){document.write("Doingthat");}functionBird(){}//ThismakesdoThat()visibleBird.prototype=Object.create(Animal.prototype);//Solution1//Youcanalsodo://Bird.prototype=newAnimal();//Solution2//Or://Bird.prototype=Anima

javascript - 为什么不应该向 JavaScript 构造函数添加功能,而是通过原型(prototype)添加功能?

我在看AddyOsmani关于构造函数模式的章节:http://addyosmani.com/resources/essentialjsdesignpatterns/book/#constructorpatternjavascript我遇到了以下情况:functionCar(model,year,miles){this.model=model;this.year=year;this.miles=miles;this.toString=function(){returnthis.model+"hasdone"+this.miles+"miles";};}//Usage://Wecancr

Javascript:函数.原型(prototype).方法

我想你们中的大多数人都看过以下代码片段:Function.prototype.method=function(name,func){this.prototype[name]=func;returnthis;};我也知道它会影响所有函数,因为它们都是由Function创建的对象,因此它们可以访问名为“method”的方法,但是我很困惑为什么Function本身也可以像下面这样访问“method”:Function.method('test',function(){return1;}); 最佳答案 Edorka的回答是正确的:函数是它自

javascript - "Found @client directives in query but no client resolvers were specified"使用客户端缓存时出现警告

我一直在关注ApolloClientdocs在地方州。我实现了一个非常简单的客户端缓存查询:exportconstGET_USER_ACCOUNTS=gql`queryGetUserAccounts{userAccounts@clientname@client}`;userAccounts和name在验证后都存储在我的缓存中:{localStorage.setItem('token',token);client.writeData({data:{isLoggedIn:true,userAccounts,name:`${givenName}${familyName}`,},});}}>并

javascript - 如何在 JavaScript 中为 Number.toFixed 编写原型(prototype)?

我需要使用JavaScript将小数四舍五入到六位,但我需要考虑旧版浏览器,所以我can'trelyonNumber.toFixedThebigcatchwithtoExponential,toFixed,andtoPrecisionisthattheyarefairlymodernconstructsnotsupportedinMozillauntilFirefoxversion1.5(althoughIEsupportedthemethodssinceversion5.5).Whileit'smostlysafetousethesemethods,olderbrowsersWILL

javascript - 为什么instanceof在原型(prototype)改变后一直说真?

instanceof运算符应该看看原型(prototype),不是吗?为什么在更改对象的原型(prototype)后它不更改答案?示例如下://The.prototypeofobjectscreatedwith'newMyKlass'//isMyKlass.prototypevarMyKlass=function(name,age){this.name=name;this.age=age;}varxx=newMyKlass('xx',20);console.log(xxinstanceofMyKlass);//true,OKxx.prototype=newString('s');con

javascript - 使用原型(prototype)/"new"的继承

这个问题在这里已经有了答案:Whywouldn'tIuseChild.prototype=Parent.PrototyperatherthanChild.prototype=newParent();forJavascriptinheritance?(3个答案)关闭7年前。大家好,我是JavascriptOO的新手,想了解更多关于继承的知识。希望大家多多指教!我看到这篇很棒的帖子:Howto"properly"createacustomobjectinJavaScript?它讨论了我在其他网站上看到的类是如何继承的,例如:functionman(x){this.x=x;this.y=2;

javascript hasOwnProperty 和原型(prototype)

functionAnimal(name,numLegs){this.name=name;this.numLegs=numLegs}Animal.prototype.sayName=function(){console.log("Himynameis"+this.name);}varpenguin=newAnimal("CaptainCook",2);penguin.sayName();for(varpropinpenguin){console.log(prop);}penguin.hasOwnProperty('sayName')结果:namenumLegssayName=>false

javascript - 将原型(prototype)附加到 JavaScript 对象

假设我有以下带有人员对象的JSON。[{"name":"Alice","age":28,},{"name":"Bob","age":33}]如果我解析它,我将得到一个包含两个JavaScript对象的数组。比方说,我想为这两个对象配备一个名为introduce的方法,它会做类似这样的事情functionintroduce(){return"Mynameis"+this.name+"andIam"+this.age+"yearsold.";}现在,我可以遍历我的两个人并调用person.constructor.prototype.introduce=introduce但是,这将在所有Ja