草庐IT

this_is_not_a_task

全部标签

javascript - jQuery .fn 表示 "not a function"

当我调用这个自定义函数时$.fn.inputBoxHelper=function(){varargs=arguments[0]||{};varmatchingElem=$.grep(this,function(e){return$(e).val()==$(e).attr('title');});$(matchingElem).addClass(args.className);this.bind({focus:function(){if($(this).val().trim()==$(this).attr('title')){$(this).val(emptyString).remove

javascript - Backbone : Id not being set to model

我尝试了以下方法来为我的模型设置一个id:varglobalCounter=1;varModel=Backbone.Model.extend({initialize:function(){this.id=globalCounter;globalCounter+=1;}});myModel=newModel();console.log(myMode.get('id'));//printsundefined如何为我的模型设置ID? 最佳答案 您需要使用set()代替函数(http://jsbin.com/agosub/1/);vargl

javascript - "$attrs is readonly", "$listeners is readonly", "Avoid mutating a prop directly"

我是Vue新手。我正在尝试开发一个聊天应用程序,其中好友列表将显示在左侧菜单上,聊天框将显示在正文中。我正在使用ajax调用加载好友列表,并根据好友ID路由到聊天框。这是代码示例。聊天列表组件将从服务器加载好友列表。这是我的app.js文件;Vue.use(VueRouter)constrouter=newVueRouter({routes,linkActiveClass:"active"});importChatComponentfrom'./components/ChatComponent';constroutes=[{path:'/chat/:id/:name',componen

javascript - "var self = this"方法背后的基本原理是什么?

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:JS:varself=this?在查看用JavaScript编写的任意代码时(例如在GitHub上),许多开发人员使用varself=this然后使用self而不是this引用当前对象。这种方法背后的基本原理是什么?

Javascript - 我如何为函数设置 'this' 变量

我有一个接受回调函数的函数。如何设置回调函数的“this”变量?例如。function(fn){//dosomestufffn();//callfn,butthe'this'varissettowindow//,howdoIsetittosomethingelse} 最佳答案 您可以使用call在对象的上下文中执行函数:fn.call(obj,'param')还有apply唯一的区别是提供参数的语法。 关于Javascript-我如何为函数设置'this'变量,我们在StackOverf

javascript - Object.create、链接和 'this'

给定以下程序,控制台日志正确-请注意链式init函数并返回此:constcat={init(sound){this.sound=sound;returnthis;},makeSound(){console.log(this.sound);}};constfluffy=Object.create(cat).init('meeeaaaauuu');fluffy.makeSound();我的问题:如何以及为什么需要returnthis才能工作?请参阅下面的错误并删除它:constcat={init(sound){this.sound=sound;//returnthis},makeSound

Javascript native 等效于 JQuery .each() & $(this)

我有以下代码,它查看每个带有.comment类的div,如果超过100个字符则缩短文本。使用JQuery。问题是如何转换为原生javascript,我找不到.each()或$(this)的等价物varshowChar=100;varellipsestext="...";varmoretext="more";varlesstext="less";$('.comment').each(function(){varcontent=$(this).html();if(content.length>showChar){varc=content.substr(0,showChar);varh=co

javascript - 从 javascript 回调中引用 "this"

我在Javascript中进行面向对象编码的方式一直困扰着我。当有回调时,我经常想引用最初调用该函数的对象,这导致我做这样的事情:MyClass.prototype.doSomething=function(obj,callback){varme=this;//ughobj.loadSomething(function(err,result){me.data=result;//ughcallback(null,me);});}首先,创建附加变量似乎总是……对我来说太过分了。此外,我想知道它是否会通过将“me”变量传回回调而最终导致问题(循环引用?非GCd对象?)。有没有更好的方法来解决

javascript - 引用错误 : Json is not defined

关闭。这个问题不符合StackOverflowguidelines.它目前不接受答案。这个问题似乎与helpcenter中定义的范围内的编程无关。.关闭9年前。Improvethisquestion我正在使用express和Node.js。当我运行下面的函数来获取URL的值时,Json.stringify(url)给我错误。ReferenceError:Jsonisnotdefined.app.get("/id",function(req,res,next){varid=req.param("id");connection.query('SELECT`url`FROMdynamic_u

javascript - JsHint - 隐藏此消息 : ES5 option is now set per default

我正在使用gulp-jshint,下面的错误消息很烦人:ES5optionisnowsetperdefault如何删除它? 最佳答案 它只是告诉您这是默认设置,因此您无需将其添加为选项。查看.jshintrc文件并删除"es5":true。http://jslinterrors.com/es5-option-is-now-set-per-default 关于javascript-JsHint-隐藏此消息:ES5optionisnowsetperdefault,我们在StackOverfl