草庐IT

this-page

全部标签

javascript - "TypeError: this is not a typed array.with"Node.js 中的 WS.js

我的服务器文件中只有这个,出现错误:constWebSocket=require('ws');constwss=newWebSocket.Server({port:9000});wss.broadcast=functionbroadcast(data){wss.clients.forEach(functioneach(client){if(client.readyState===WebSocket.OPEN){client.send(data);}});};wss.on('connection',functionconnection(ws){ws.on('message',functi

javascript - ES6 类中的 ES6 函数、箭头函数和 'this'

这个问题在这里已经有了答案:ShouldIwritemethodsasarrowfunctionsinAngular'sclass(3个答案)ArrowvsclassicmethodinES6class(1个回答)关闭4年前。classAppextendsComponent{constructor(props){...}onChange=(e)=>this.setState({term:e.target.value})onSubmit(e){e.preventDefault();constapi_key="C1hha1quJAQZf2JUlK";consturl=`http://api

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 - 如何选择不是 '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 - 有没有办法检测用户是否在 beforeunload 事件中按下了 "Stay on page"或 "Leave page"?

有什么方法可以让我在以下代码中检测到用户点击了“离开页面”或“留在页面”按钮?$(window).on('beforeunload',function(){return"Yousavesomeunsaveddata,Doyouwanttoleave?";}); 最佳答案 通过一些技巧,您至少可以确定用户是否留下来了。如果用户离开了页面,您对此无能为力:vartimeout;$(window).on('beforeunload',function(){timeout=setTimeout(function(){//userstayed

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 - 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 - 服务 worker : Fetch event listener only works after page reload

我已经使用以下代码在我的页面中添加了一个服务worker。一旦页面被重新加载并且worker已经安装,它就可以很好地工作。但是在我看到'SWINSTALL'日志后,在重新加载页面之前似乎没有捕捉到任何获取事件。app.jsnavigator.serviceWorker.register('/worker.js').then((registration)=>{console.log('ServiceWorkerregistrationsuccessfulwithscope:',registration.scope);},(err)=>{console.log('ServiceWorker