草庐IT

send_this_email

全部标签

javascript - 使用 `prototype` 而不是 `this` 的原因

我正在使用Lightbox2https://github.com/lokesh/lightbox2/blob/master/js/lightbox.js而且我不明白为什么Lightbox的所有内部成员都是原型(prototype)(Lightbox.prototype.init)而不是简单的成员(Lightbox.init)?如果它们特定于lightbox的每个实例,使用this.init不是更容易吗? 最佳答案 困惑?不要...这样想:Lightbox是您的类定义,但它还不是一个实例。任何你直接放在类上的东西都像一个静态成员:Li

javascript "this"再次指向 Window 对象

我在JavascriptthispointstoWindowobject上问了一个问题关于“this”指向Window对象。这里是源代码vararchive=function(){}archive.prototype.action={test:function(callback){callback();},test2:function(){console.log(this);}}varoArchive=newarchive();oArchive.action.test(oArchive.action.test2);TimDown写道“但是该函数随后使用callback()调用,这意味着

javascript - 在 jQuery 中,this.each() 是如何工作的?

为了让我的问题更具体,我阅读了.each()forjQuery的文档,但我有点困惑。我有这段代码:$.fn.imgAreaSelect=function(options){options=options||{};this.each(function(){if($(this).data('imgAreaSelect')){if(options.remove){$(this).data('imgAreaSelect').remove();$(this).removeData('imgAreaSelect');}else$(this).data('imgAreaSelect').setOpt

javascript - React : this.状态在for循环中消失

如何将this带入我的.map()循环?它似乎消失了。:-(我正在创建一个“动态表单”,用户可以在其中为其表单指定多行输入。我想遍历state.items[]中的所有项目并为它们构建表单输入字段。例如,表单以“field”和“autocomplete_from”开头。然后用户可以单击添加新行以在其表单中获取更多行。102render:function(){103return(104105{this.state.items.map(function(object,i){106return(107109110State.autocomplete_from:{this.state.autoc

javascript - $timeout 函数中的 AngularJS 'this' 引用不起作用

我有一个让我发疯的AngularJS问题。我有一个看起来像这样的服务(这是一个说明问题的例子)varapp=angular.module('test-module');app.service('ToolService',function($timeout){this.doSomething=function(){console.log("yunoreferencedasmethod?!?");}this.runTimeoutExample=function(){$timeout(function(){this.doSomething();},1000);}})我的Controller看

javascript - this.props.history 已弃用( react 路由器)

我试图以编程方式导航到另一个页面,就像这样this.props.history.push('/new-path');它有效,但我在控制台中收到弃用警告说:警告:[react-router]props.history和context.history已弃用。请使用context.router。此处有更多信息https://github.com/reactjs/react-router/blob/master/upgrade-guides/v2.0.0.md#changes-to-thiscontext之后我尝试像这样使用这个新方法this.context.router.push('/new

javascript - 为什么 *this* 不是 *this*?

我刚刚写了这段代码来表示这个让我丧命的错误(Grrr!)我想知道为什么当我得到error:methodundefined时,我已经在Safari中检查过,parserDidStart()方法中的这个变量不是EpisodeController类型,而是EpisodeFeedParser类型,这是为什么?varEpisodeFeedParser=function(url){this.url=url;this.didStartCallback=null;};EpisodeFeedParser.prototype.parse=function(doc){this.didStartCallbac

javascript - 如何使用带有 "this"的 javascript 提交表单

有什么方法可以提交我有这样的href链接的当前表单Save我想在任何地方都使用相同的代码,所以我不能使用任何id或类 最佳答案 使用this.form.submit()提交表单即在你的情况下它会像Save但强烈建议使用表单名称否则,如果您习惯使用jquery,您也可以使用jqueryclosest功能$(field).closest("form").submit(); 关于javascript-如何使用带有"this"的javascript提交表单,我们在StackOverflow上找到

javascript - 未处理的 promise 拒绝警告 : This error originated either by throwing inside of an async function without a catch block

我的Node-Express应用出现以下错误UnhandledPromiseRejectionWarning:Unhandledpromiserejection.Thiserrororiginatedeitherbythrowinginsideofanasyncfunctionwithoutacatchblock,orbyrejectingapromisewhichwasnothandledwith.catch().(rejectionid:4)至少可以说,我创建了一个看起来像这样的辅助函数constgetEmails=(userID,targettedEndpoint,headerA

javascript - this.name 在 javascript 中返回 undefined

我正在尝试远程创建一个onclick对于每个(以节省打字时间)。这是window.onload()功能:window.onload=function(){divel=document.getElementsByTagName('div');for(varelindivel){divel[el].onmouseover=function(){this.style.textDecoration="underline";};divel[el].onmouseout=function(){this.style.textDecoration="none";};divel[el].onclick=