草庐IT

this_call

全部标签

javascript - this.route() 和 this.resource() 有什么区别?

我知道路由用于将URL映射到模板,但显然您可以使用this.route或this.resource定义路由App.Router.map(function(){this.route("about",{path:"/about"});this.route("favorites",{path:"/favs"});});App.Router.map(function(){this.resource('posts',{path:'/posts'},function(){this.route('new');});});如果您想为路线定义子路线,您是否只使用this.resource还是有其他我没有

javascript - Safari 扩展 : WebSocket connection failure calls onclose and not onerror and no exception

我正在为Firefox、Chrome和Safari编写浏览器扩展。当尝试使用没有服务器监听特定端口的Safari扩展连接到WebSocket服务器时,我的Safari扩展不会引发异常,也不会调用onerror。相反,正在调用Safari扩展的onclose处理程序。我还在控制台中看到此消息:[Error]WebSocketnetworkerror:Theoperationcouldn’tbecompleted.Connectionrefused(global.html,line0)在Firefox和Chrome上,它似乎可以正确处理它AFAIK并调用onerror。我只是在做这样的事情

javascript - array.forEach.call 与 array.map.call

要在JavaScript中遍历querySelectorAll的结果,以下哪一项比另一项更可取?[].forEach.call(document.querySelectorAll('div'){//dosomething})[].map.call(document.querySelectorAll('div'){//dosomething})本质上,我想知道这些是否都实现了提供对从querySelectorAll返回的每个dom元素的访问的相同结果。如果是这样,人们可能想要使用一个而不是另一个的原因是什么? 最佳答案 forEach

javascript - "this"在构造函数中分配的函数中如何工作?

我找到了这个示例代码:functionpersonFullName(){returnthis.first+''+this.last;}functionPerson(first,last){this.first=first;this.last=last;this.fullName=personFullName;}vardude=newPerson("Michael","Jackson");alert(dude.fullName());这会提醒“MichaelJackson”。我将其更改为从构造函数调用personFullName而不是分配函数对象:functionpersonFullNa

javascript - bind 和 var self=this 的区别?

在我的Reactnative代码中,我在多个模块的多个位置同时使用了bind(this)和varself=this;。两者都解决了在正确位置解析this关键字的问题。这是我的代码(执行相同功能的2个代码)-使用bind(this)retval.then(function(argument){console.log("argument"+JSON.stringify(argument));this.stateSetting(argument);}.bind(this));使用varself=thisvarself=this;retval.then(function(argument){c

javascript - foo.toString() 和 Object.prototype.toString.call(foo) 有什么区别?

如果我定义一个函数:functionfoo(){alert(this.x);}我可以通过调用foo函数的toString方法来打印函数定义。console.log(foo.toString())输出:functionfoo(){alert(this.x);}如果我然后运行console.log(Object.prototype.toString.call(foo))输出:"[objectFunction]"令我惊讶的是输出结果不同。我认为这两种形式是等价的吗?即foo函数从顶级Object继承了toString方法并使用Object.prototype.toString.call(fo

javascript - d3.select(this) 返回什么?

我有一个svg组,我在其上调用拖动函数。varcontainer=d3.select("#id");container.call(dragcontainer);vardragcontainer=d3.drag().on("start",function(){}).on("drag",function(d,i){//(d3.select(this)).select("rect");}).on("end",function(){});显然,d3.select(this)不返回容器,但是它们相似(通过属性检查),但不完全相同。为什么会这样?如何在被调用函数中访问container?

javascript - 为什么 (function(){return this}).bind ('abc' )()== ='abc' 等于 false?

假设我有一个这样的函数:varf1=function(){returnthis;};console.log(f1.bind('abc')()==='abc');据我所知,f1.bind('abc')应该创建一个返回'abc'的新函数,所以我猜它的输出应该与console.log('abc'==='abc')这是真的,但现在输出是假的,我的猜测有什么问题吗? 最佳答案 在非严格模式下,原始值被包裹在对象中。所以,'abc'变成了newObject('abc')。在严格模式下,这不会发生。'usestrict';varf1=functi

javascript - 使用 this.state 在渲染中设置状态

我最近看到这种类型的react模式,其中使用this.state在渲染中设置状态:classShowMeextendsReact.Component{constructor(props){super(props);this.state={showButton:false,};}render(){if(this.props.show){this.state.showButton=true;//settingstateinrender!!}return(Showorhidebutton{this.state.showButton&&})}}这似乎是一种反模式。这会导致错误吗?不过它似乎工作

JavaScript 对象 : Why Doesn't This Work?

我写了下面的代码。它没有给我答案,而是输出NaN。我希望代码返回John和Mark的权重。请解释。'usescript';//DeclaringvariablesvarinfoJohn;varinfoMark;varbmiCalculator;varhigherBmi;bmiCalculator=function(height,mass){varcalculatedBmi;calculatedBmi=mass/(height*height);returncalculatedBmi;};infoJohn={name:'John',mass:85,height:110,bmi:bmiCal