草庐IT

function-style

全部标签

javascript - JavaScript 中 Number 和 Function.prototype 之间的关系是什么?

我正在阅读Javascript:theGoodParts这本书。当我阅读下面的代码时,我有点困惑:Function.prototype.method=function(name,func){this.prototype[name]=func;returnthis;};Number.method('integer',function(){returnMath[this我认为上面代码的第一部分意味着JavaScript中的任何函数现在都有一个名为method的方法。但是“数字”也是一个函数吗?为什么Number.method有意义?我假设Number继承了Number.prototype,

javascript - react 代码抛出 “TypeError: this.props.data.map is not a function”

我刚开始用React编码,我习惯用CoffeeScript编码。我试着沿着tutorialpresentedintheReactdocs编码并为状态更新做了类似的事情。但是,我收到TypeError:this.props.data.mapisnotafunction。我有点迷茫,想知道我哪里错了。有人可以指导我并告诉我哪里出错了吗?这是我的代码:(function(){varStatus,StatusBox,StatusForm,StatusList,button,div,h4,textarea,_ref;_ref=React.DOM,div=_ref.div,textarea=_re

javascript - 如何使 "undefined is not a function"错误更有用?

考虑这段JavaScript代码:varx=newdate()//"ReferenceError:dateisnotdefined"-usefulerror,hintsatatypo('D'ate)varx=newMyClass.foo()//"TypeError:undefinedisnotafunction"-baderror,nohintitmightbe'F'oo错误本身是正确的,因为MyClass没有foo方法,所以MyClass.foo确实返回了undefined,new不喜欢这样。问题是这根本没有暗示用户可能拼错了方法名称。现实生活中的例子:newMeteor.colle

javascript - 火狐插件 : How to override native js function

我正在尝试使用pageMod在页面加载时运行脚本:但我看不到它的效果vardata=require("sdk/self").data;varattachTo=require("sdk/content/mod").attachTo;varpageMod=require("sdk/page-mod");pageMod.PageMod({include:"*",contentScriptWhen:"start",allow:true,attachTo:["existing","top"],contentScriptFile:[data.url("jquery-2.1.1.min.js"),d

javascript - Chrome : Call Javascript function from (system) command line?

我需要通过命令行从在GoogleChrome/Chromium中运行的网站调用Javascript函数。是否有可能通过命令行从外部访问开发者工具?是否有可用于执行代码的扩展?最方便的方法是从命令行访问Chrome开发者控制台。编辑:为了更清楚:假设我所在的网站定义了这个函数:functionhello(){alert("hello");}我想调用此函数,但我无法访问Chrome中的开发人员工具。我只能访问MacOSX终端(通过SSH)。这是一个没有键盘的画廊设置。可能需要某种管道。 最佳答案 经过更多研究,我找到了crconsole

javascript - 基于 Blob 的 'link stylesheet' 与标准 'style' 标签

我想知道使用样式作为Blob链接有什么好处和区别:在标准标签上:...我的意思是像这样创建Blob:varblob=newBlob([css_here],{type:'text/css'});varlink=document.createElement('link');link.rel='stylesheet';link.href=window.URL.createObjectURL(blob);head.appendChild(link);提前致谢。 最佳答案 内存管理如果你把东西放在style中,然后删除-它就不见了。但是,如果

javascript - 如何解决 Component should be written as a pure function error in eslint-react?

constHeader=React.createClass({contextTypes:{router:React.PropTypes.object.isRequired,},render(){return(AB);},});我使用eslint-config-airbnb检查上面的代码,它向我显示一条错误消息,例如Componentshouldbewrittenasapurefunction。那么如何将上面的组件改成纯函数呢?感谢您的帮助。 最佳答案 当你有一个“哑”组件(没有内部状态、生命周期方法等)时,你可以将它写成一个简单的j

javascript - 使用 Styled-Components,如何在 Styled Component 之外设置颜色数组?

theme.js-我有一个Styled-Components主题,其中包含我应用的所有颜色变化。constcolors={purples:{60:'#AEA',50:'#GSA',},blues:{20:'#asd',5:'#fasd',}...然后我有一个UI组件,我需要在其中按特定顺序定义一组颜色:importReactfrom'react';constcolors=['#GSA','#AEA','#asd','#fasd','#AEA'];我稍后使用此colors数组根据状态找到要在我的组件中使用的正确颜色:constgetBackgroundColor=({currentPos

javascript - 设置多个 style.background 值

我想在我的背景中使用渐变并且是跨平台的我想设置带有vendor前缀的背景:background:-webkit-linear-gradient(red,blue);background:-o-linear-gradient(red,blue);background:-moz-linear-gradient(red,blue);background:linear-gradient(red,blue);如何在HTMLElement上设置多个style.background,使用Javascript来支持vendor前缀?更新:我不想使用jQuery或任何其他外部库。

javascript - Ant 设计错误 : "Form.create() getFieldDecorator is not a function"

"antd":"^1.11.1","react":"^15.1.0","react-dom":"^15.1.0",错误:未捕获类型错误:getFieldDecorator不是函数Ant设计演示:https://ant.design/components/form/importReact,{Component}from'react';import{Form,Icon,Input,Button}from'antd';constFormItem=Form.Item;constHorizontalLoginForm=Form.create()(React.createClass({handle