草庐IT

FUNCTION_LIST

全部标签

javascript - 构造函数 : var X = function (){}, var X = function X(){} 和 function X(){} 的区别

这个问题在这里已经有了答案:varfunctionName=function(){}vsfunctionfunctionName(){}(41个回答)关闭8年前。我现在正在调试别人的代码,当他在这两种模式下定义构造函数时,我感到很困惑。两者之间有什么特别之处吗?//constructor1varMyObject=function(){};//constructor2varMyObject=functionMyObject(){};另外,像这样创建一个函数有什么效果。functionMyObject(){};我只是在查看每个的特定用例。

javascript - 直接在函数声明上使用 function.prototype.bind

为什么允许这样做?varf=function(){console.log(this.x);}.bind({x:1})();为什么这不是或更好,为什么我在这种情况下会出现语法错误?functionf(){console.log(this.x);}.bind({x:1})();那么,为什么我需要函数表达式语法来完成这项工作,有没有办法直接在函数声明上使用bind方法? 最佳答案 第二个示例有效,但语法略有偏差:将函数括在括号中。我不得不说我不完全确定为什么。好像没有parent也行吧?:P(functionf(){console.log

javascript - CSS 和 JavaScript : Get a list of CSS custom attributes

来自这段代码:HTMLCSS.test{background-color:red;font-size:20px;-custom-data1:value1;-custom-data2:150;-custom-css-information:"loremipsum";}使用javascript——例如从$('.test')——我如何才能得到一个CSS属性列表,其属性名称以前缀“-custom-”开头“?(他们可以有不同的名字,但总是相同的前缀)我想得到这个:{customData1:"value1",customData2:150,customCssInformation:"loremip

javascript - 使用: and => for the return type with a TypeScript function?有什么区别

我有以下代码:///functionaddThemePrototypes(){vartemplateSetup=newArray();$.fn.addTemplateSetup=function(func,prioritary){if(prioritary){templateSetup.unshift(func);}else{templateSetup.push(func);}};}有人能告诉我为什么要用=>void来声明吗?interfaceJQuery{addTemplateSetup:(func:Function,priority:bool)=>void;}我想我对如何从java

javascript - 哪种方法更好 : function. apply(<this>, args) 或具有接受 <this> 作为参数的函数?

假设我有一个这样定义的函数A:functionA=function(myObject,someParams){myObject.save_some_data=someParams;myObject.processed=true;}然后我可以调用它并传递一个对象作为functionA(someObject,someParams)进行处理。不过,我可以用apply()转换这个例子:functionA=function(someParams){this.save_some_data=someParams;this.processed=true;}functionA.apply(someObj

javascript - Array.find(value) 返回值 'is not a function'

我正在尝试在AngularJS数组上使用JavaScript的find()函数。这是合法的,对吧...?这个非常简单的代码给我带来了一些问题。这是说$scope.names.find(name1)的返回值不是函数。TypeError:Name1不是函数if($scope.names.find(name1)!==name1){$scope.names.push(name1);}我也试过...if($scope.names.find(name1)===undefined){$scope.names.push(name1);}和if(!$scope.names.find(name1)){$s

javascript - 如何在 Chrome 打包应用程序的 list 中使用 "system_indicator"?

我正在尝试创建一个在系统菜单栏中带有图标的Chrome包应用程序,如下所述:https://docs.google.com/document/d/1QhhfR33Y28Yqnnoa_Sl3fnZK_mKtwt4dZe6kNyJ_MjU/edit,GoogleHangout应用程序可以实现此功能(这不是完全相同的行为),但我找不到任何好的文档来执行相同的操作。在GooglePackagedApp的manifest页面中,我们可以看到“system_indicator”字段。是我要找的吗?当我尝试将此字段设置为图标的url时,Chrome返回此错误:'system_indicator're

javascript - 为什么我在运行此示例 node.js 代码时得到 "TypeError: object is not a function"?

为什么我在运行下面显示的代码时会出错?(它用于Coursera上斯坦福“创业工程”类(class)的作业之一:https://class.coursera.org/startup-001/quiz/attempt?quiz_id=149)该类(class)于2013年6月至9月开课,因此可能存在破坏脚本的Node或csv更新,对吧?作业不是关于修复脚本的,所以这个问题不是'作弊',而且类(class)目前没有运行..所以,环境是:Ubuntu14.04(内核3-13-0-29-generic),Nodev0.11.13,npmv1.4.9我在主目录中有npminstall的csv、ac

javascript - ES6/终极版 : returning a function to remove event listener

我在Egghead上观看DanAbramov的Redux教程,他做了一些让我有点困惑的事情。作为学习练习,他让观众重建createStore抽象。createStore提供的一种方法是subscribe,它会添加监听器以监听商店的变化。然后他说:Thereisanimportantmissingpiecehere.Wehaven'tprovidedawaytounsubscribealistener.InsteadofaddingadedicatedUnsubscribemethod,we'lljustreturnafunctionfromtheSubscribemethodthatr

javascript - "TypeError: res.sendStatus is not a function"为什么我在一段时间后收到此错误?

我已经使用npm安装了“express”,我已经成功地在3000上监听了端口号。但是过了一会儿我得到了以下错误,TypeError:res.sendStatusisnotafunction我们知道,res.sendStatus(404)与express相关。但是express的位置很清楚。这是app.js中的源代码varexpress=require('express'),app=express();app.get('/',function(req,res){res.send('HelloWorlds');});app.use(function(req,res){res.sendSta