草庐IT

enable_shared_from_this

全部标签

JavaScript this.window 不等于窗口

考虑以下顶级javascript代码:if(this.window===window)alert('same');elsealert('different');//alerts:different为什么this.window和window不严格相等?我还在表达式的右侧尝试了“this”并得到了相同的结果。 最佳答案 在InternetExplorer中(8.0.7600是我测试过的),没有限定符的this实际上解析为全局窗口对象。在我尝试过的所有其他浏览器(Chrome、Firefox、Opera)中,this.window===w

javascript - 关于 this/@ 在 Javascript/Coffeescript 中的一个难题

我正在研究TrevorBurnham的CoffeeScript一书,我遇到了一个关于this/@的奇怪谜题。这个谜题有几个部分(我可能会很困惑),所以我会尽量把它说清楚。我遇到的主要问题是,通过不同的REPL和解释器运行相同代码时,我得到了不同且不一致的结果。我正在测试(1)coffeeREPL和解释器,(2)Node的REPL和解释器以及(3)v8的REPL和解释器。这是代码,首先是Coffeescript,然后是Javascript://coffeescriptsetName=(name)->@name=namesetName'Lulu'console.lognameconsole

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 - 如何选择不是 'this' 的元素?

我有所有具有相同类的div列表,我想对所有不是被点击的div应用一个函数(this),我如何选择!this使用jQuery?更新:我做了这个但它不起作用,知道为什么吗?$("li").each(function(){$("li").not(this).click(function(e){$(this).hide();});});更新2:这是完整的实际代码:$(".mark").click(function(e){e.preventDefault();varid="#"+$(this).parent().parent().parent().parent().attr("id")+"";v

javascript - 为什么 jQuery 中的 "this"参数返回带有 anchor 的 href

我有这个例子:HelloHello还有这两行jQuery:jQuery("a").filter(function(){console.log(""+this+"")});返回:http://www.google.com/#1http://www.google.com/#4但是jQuery("a").filter(function(){console.log(this);});返回Hello​Hello​为什么第2行返回anchor的HREF属性IF'this'参数添加一个“字符串”?jQuery文档说如果过滤器有一个函数参数,“this”是当前的DOM元素

javascript - 当您在 Ember 函数上绑定(bind) 'this' 时会发生什么?

我正在努力更好地理解thisFirebaseauthenticatorforEmberSimpleAuth:importEmberfrom'ember';exportdefaultEmber.Controller.extend({actions:{login:function(){this.get('session').authenticate('authenticator:firebase',{'email':this.get('email'),'password':this.get('password')}).then(function(){this.transitionToRou

javascript - react .js : onClick function from child to parent

我用了this以文章为例(React方式),但它对我不起作用。请指出我的错误,因为我不明白哪里出了问题。这是我看到的错误:UncaughtTypeError:this.props.onClickisnotafunction这是我的代码://PARENTvarSendDocModal=React.createClass({getInitialState:function(){return{tagList:[]};},render:function(){return({this.state.tagList.map(function(item){return()})})},HandleRem

javascript - Uncaught TypeError : this. y.rangeBand 不是迁移到 D3 版本 4 后的函数

我正在尝试将我的代码从D3版本3迁移到版本4。这是我的版本3的代码:this.x=d3.scale.linear().range([0,this.width]);this.y=d3.scale.ordinal().rangeRoundBands([-20,this.yItemsHeight],.1,1);this.xAxis=d3.svg.axis().scale(this.x).orient("top");this.yAxis=d3.svg.axis().scale(this.y).orient("left");...this.svg.selectAll(".bar").data(d

javascript - 避免 javascript 的 "this"错误的最佳方法

在某些情况下,this关键字可能不是我期望的对象。(最近的例子:inankeyevent,inmyXBL)避免此类错误的最佳方法是什么?目前,我一直使用jQuery中的$.fn来存储我的变量,但我不确定这是否是最佳方法。 最佳答案 了解this的行为方式和原因,然后阅读您正在处理的代码。不要相信一些神奇的功能,如果您不知道/阅读代码,您可能总是会得到意想不到的结果。对于这个“问题”,根本没有单一的出色解决方案。 关于javascript-避免javascript的"this"错误的最佳方

javascript - Expressjs : How to share route middleware accross routes

我已经定义了多个路由中间件,并希望在多个路由/Controller之间共享它们。这是我的设置:app.js需要./routes/index.js://loadfsmodulevarfs=require('fs');//importroutingfilesmodule.exports=function(app){fs.readdirSync(__dirname).forEach(function(file){if(file=="index.js")return;varname=file.substr(0,file.indexOf('.'));require('./'+name)(app)