草庐IT

new_class

全部标签

javascript - "newing"JavaScript 中的一个函数 - 它是什么意思?

考虑以下代码:varf=function(){return10;}typeoff;//returns"function"f();//returns10varg=f;g();//returns10,obviouslyvarh=newf;h;//consoleevaluatestof-????h();//Typeerror-called_non_callabletypeofh;//returns"object"那么,这里的h是什么?Chrome控制台似乎将其评估为f,但它不可调用。"new"这样的功能是什么意思?h现在与f有什么关系?顺便说一句,这两行看起来是等价的:varh=newf;v

javascript - new Date() 中的日期参数错误?

有人可以解释一下,为什么我在运行下面的代码时会得到12Februray吗?我看到天是从1到31,只有月份是0开头vard=newDate(2100,1,13)>dFri,12Feb210023:00:00GMT编辑:为什么这次??23:00:00应该是00:00:00 最佳答案 您的语言环境时区有干扰。尝试:newDate(Date.UTC(2100,1,13))。 关于javascript-newDate()中的日期参数错误?,我们在StackOverflow上找到一个类似的问题:

javascript - 微小的MCE 4 : add Class to selected Element

我创建了一个tinymce菜单项,我想要它做的是向选定的文本元素添加一个类。我似乎无法弄清楚如何做到这一点。有什么建议么?添加我的菜单项如下所示:tinymce.PluginManager.add('button',function(editor,url){editor.addMenuItem('button',{icon:'',text:'Button',onclick:function(){tinyMCE.activeEditor.dom.addClass(tinyMCE.activeEditor.selection,'test');//notworking},context:'i

javascript 奇怪的语法 : c. name=i+ +new Date;

来自colorpowered.com的colorboxv1.3.15在它的缩小代码中有这个javascript:c.name=i++newDate;这似乎运行得很完美,不是吗? 最佳答案 一元+运算符用于通过从对象调用valueOf()将对象转换为数字。如果未返回数字,则操作返回NaN您可以通过为任何对象编辑valueOf函数来自定义它,如下所示:varfoo={};foo.valueOf=function(){return9001;};console.log(+foo);//9001Date的valueOf()只返回getTime

javascript - 原型(prototype)复制 vs Object.create() vs new

我在使用继承时注意到可以通过三种方式获得相同的结果。有什么区别?functionAnimal(){}Animal.prototype.doThat=function(){document.write("Doingthat");}functionBird(){}//ThismakesdoThat()visibleBird.prototype=Object.create(Animal.prototype);//Solution1//Youcanalsodo://Bird.prototype=newAnimal();//Solution2//Or://Bird.prototype=Anima

javascript - 带有 ng-repeat 的 Angular 切换表行 ng-class

这似乎不适合我。我在tr上有一个ng-repeat、ng-click和ng-class。单击tr应将类切换为.error。当前单击tr将更改所有表格行的类。.is-grey-true{background-color:#ccc;}.error{background-color:red;}{{student.id}}{{student.firstname}}{{student.lastname}}varstudentApp=angular.module('studentApp',[]);studentApp.controller('StudentController',function(

javascript - Bluebird.JS Promise : new Promise(function (resolve, reject){}) vs Promise.try(function(){})

我什么时候应该使用哪个?以下是一样的吗?新的Promise()示例:functionmultiRejectExample(){returnnewPromise(function(resolve,reject){if(statement){console.log('statement1');reject(thrownewError('error'));}if(statement){console.log('statement2');reject(thrownewError('error'));}});}Promise.try()示例:functiontryExample(){return

javascript - 10 秒后添加类(class)

我有一个div,当我点击它时,它会添加一个“播放”类。然后,10秒后,我想添加一个“finished”类。我有这段代码,但我该如何计时才能在10秒后添加finsihed类?$('.albumsimg').on('click',function(){$(this).addClass('playing');});感谢任何帮助!非常感谢大家。我用这个问题向HackerYou的~30名学生展示如何使用stackoverflow从社区获得一流的帮助。 最佳答案 尝试使用setTimeout指定10秒延迟。$('.albumsimg').on(

javascript - `new Function("在立即调用的函数中返回 this")()` 的目的是什么

我正在查看setImmediatepolyfill它包含在立即调用函数中,包含以下内容:(function(global,undefined){"usestrict";...}(newFunction("returnthis")()));我对最后一条语句的目的和传递给函数的参数感到困惑。这段代码既可以在浏览器中运行,也可以在Node.js上运行,这与它有什么关系吗?你能解释一下吗? 最佳答案 代码的编写使其可以访问全局范围,无需知道包含该范围的对象是什么。例如,在浏览器中,全局范围是window,但在其他容器中并非如此。通过使用Fu

javascript - 使用原型(prototype)/"new"的继承

这个问题在这里已经有了答案:Whywouldn'tIuseChild.prototype=Parent.PrototyperatherthanChild.prototype=newParent();forJavascriptinheritance?(3个答案)关闭7年前。大家好,我是JavascriptOO的新手,想了解更多关于继承的知识。希望大家多多指教!我看到这篇很棒的帖子:Howto"properly"createacustomobjectinJavaScript?它讨论了我在其他网站上看到的类是如何继承的,例如:functionman(x){this.x=x;this.y=2;