草庐IT

function-constructor

全部标签

javascript - 谷歌地图 API v3 - TypeError : Result of expression 'google.maps.LatLng' [undefined] is not a constructor

我正在创建一个静态html页面来显示数据中的多个位置。我刚刚复制了其中一个示例并正在向后工作,但我在Safari检查器中收到以下错误:main.js:1SyntaxError:Parseerrorsample.htm:10TypeError:Resultofexpression'google.maps.LatLng'[undefined]isnotaconstructor.这是我的html代码:MultiMarkersSampleviaGoogleMapsfunctioninitialize(){varmyLatlng=newgoogle.maps.LatLng(-30.2965590

javascript - 以下JavaScript中 "i"中的 "function(i)"是什么?

在下面的代码中有“function(i)”,但是在这个语句之前的任何地方都没有声明“i”。ul.css({width:10,overflow:'visible'}).retarder(100,function(i){i.css('visibility','visible').animate({width:ul[0].wid,left:-50},{duration:500,complete:function(){ul.css('overflow','visible');}});});看起来它可能类似于c++的“this”语句。这完全正确吗? 最佳答案

javascript - 为什么我要在 jQuery(function ($) { }); 中封装一个 jQuery 函数?

我遇到了一段代码,看起来像这样:jQuery(function($){$('#saySomething').click(function(){alert('something');});});我不太明白。为什么我不能简单地这样做:$('#saySomething').click(function(){alert('saySomething');}); 最佳答案 jQuery(function($){...});是以下内容的简写形式:jQuery(document).ready(function($){...});如果您不等待文档准备

JavaScript 语法 : function calls and using parenthesis

为什么会这样..但不是这个????区别在于调用myAlert函数时使用括号。我得到的错误.."htmlfile:Typemismatch."whencompilingviaVS2008. 最佳答案 函数后面的()表示执行函数本身并返回它的值。没有它,您只是拥有函数,它可以作为回调传递。varf1=function(){return1;};//'f1'holdsthefunctionitself,notthevalue'1'varf2=function(){return1;}();//'f2'holdsthevalue'1'becau

javascript - 什么是 (function (x,y){...})(a,b);在 JavaScript 中是什么意思?

我看到了这个函数:(function(x,y,data,lbl,dot){//Functionbody...})(x,y,data[i],labels[i],dot);这是什么?功能?为什么要将函数定义放在()中? 最佳答案 在javascript中你可以有anonymous和selfinvoking函数。functionadd(a,b){returna+b;}与相同varadd=function(a,b){returna+b;}你称这些为add(10,20)您可以定义函数并立即调用它(function(a,b){returna+b

javascript - Javascript 函数定义中的句点 (function window.onload(){})

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:JavaScriptFunctionSyntaxExplanation:functionobject.myFunction(){..}我最近看到了一些(遗留的)javascript代码,如下所示:functionwindow.onload(){//somecode}这对我来说看起来不像有效的javascript,因为您不能在标识符中使用句点,但它似乎在IE8中有效。我假设它相当于:window.onload=function(){}我在Chrome和IE9中尝试过相同的代码,但它们都引发了语法异常,所以我认为

javascript - "function*()"在nodejs中是什么意思?

这个问题在这里已经有了答案:Whatis"function*"inJavaScript?(4个答案)关闭8年前。我遇到了这个惯用语:function*(){...}来自这个页面https://github.com/jmar777/suspend并且不确定它是做什么的。谁能解释一下?谢谢!

javascript - 为什么 jslint 更喜欢 {}.constructor(obj) 而不是 Object(obj)

两者都将检测对象而不是基元。这似乎是纯粹的句法差异。//jslintprefers{}.constructor(obj)overObject(obj)//calledisObjectbyunderscore//willtestonlyforobjectsthathavewritablekeys//forexamplestringliteralswillnotbedetected//butarrayswillvarisWritable=function(obj){return{}.constructor(obj)===obj;}; 最佳答案

javascript - IIFE void function() vs (function()) 在括号中使用 void 与包装的区别

创建模块的常见做法是将它们包裹在括号中,这样您就不会在模块外泄漏任何变量(在连接等时)。还有void运算符,它计算给定的表达式并返回undefined。(参见MDN)我想知道更喜欢在括号中包装函数而不是使用void的原因是什么。它是历史的,它是否与串联有关,否则?我知道当其中一个文件缺少分号时,您可能会遇到连接问题,这会导致严重的问题,直到您注意到为止。例子例如,module1.js(注意缺少的逗号):(function(){returnfunction(){console.log('module1.Ishouldnotbecalled');};})()和module2.js:(fun

javascript - react : 'this.state' is undefined inside a component function

我在组件内的函数中访问this.state时遇到问题。我已经找到了this关于SO的问题并将建议的代码添加到我的构造函数中:classGameextendsReact.Component{constructor(props){super(props);...this.state={uid:'',currentTable:'',currentRound:10,deck:sortedDeck};this.dealNewHand=this.dealNewHand.bind(this);this.getCardsForRound=this.getCardsForRound.bind(this)