jjzjj

instance_variable

全部标签

javascript - 代码挑战 : Create a class Foo that tracks the number of total object instances

我正在尝试解决工作应用程序的代码挑战,但我遇到了困难,非常感谢任何帮助。问题:创建一个Foo类,它有一个名为refCount的方法。在类或其任何实例上调用refCount应该返回存在的实例总数。示例:varf1=newFoo();f1.refCount();//shouldbe1Foo.refCount();//shouldbe1varf2=newFoo();f1.refCount();//shouldbe2f2.refCount();//shouldbe2Foo.refCount();//shouldbe2到目前为止我有这样的事情:functionFoo(){this.refCoun

javascript - 为什么 typescript 不提示某些 undefined variable

我有以下示例:classUncle{constructor(publicname:string){}talk(){return"Hellomynameis"+name;}}letp:Uncle=newUncle("Jo");console.log(p.talk());对于某些变量名,typescript(目前版本2.1.4)不会提示它们没有在您的程序中定义(在方法讨论中,名称是在没有这个的情况下使用。)。name就是其中之一。如果我将变量重命名为firstName,编译器会正确地提示...errorTS2663:Cannotfindname'firstName'.Didyoumeant

javascript - JavaScript 中全局作用域中存在 undefined variable 的原因是什么?

我发现很多关于undefined作为值的讨论,例如如何检查是否相等等等。但是undefined作为全局变量存在的“工程”原因是什么?对面没有null变量...console.log(undefinedinthis);//logstrueconsole.log(nullinthis);//logsfalse 最佳答案 在JavaScript中,null是一个保留字;undefined不是,但由环境实现作为一个全局变量,其值为undefined。您会注意到您可以更改undefined的值,但不能更改null的值,except严格模式(会

javascript - 三.Object3D.add : object not an instance of THREE. Object3D

所以我遇到了这个错误,但我找不到它的来源。我相信这与我在场景中导入和创建3d对象有关,但我不确定我做错了什么。代码如下:我在调用init之前调用此函数functionloadObjects(){loader=newTHREE.JSONLoader();varfloorDiskmaterial=newTHREE.MeshPhongMaterial({map:THREE.ImageUtils.loadTexture('img/floor_test.jpg'),transparent:true,color:0xeaeaea,ambient:0xeaeaea,overdraw:0.5,//sp

Javascript : Modifying Prototype doesn't affect existing Instances

这个问题在这里已经有了答案:OverwritingandExtendingPrototype(1个回答)关闭5年前。我创建了原型(prototype)的2个实例,更改了原型(prototype)中的函数,更改反射(reflect)在两个实例中(很棒)。但是,当我通过删除该函数修改原型(prototype)时,该函数对于现有实例仍然存在。functionA(){this.name="cool";}A.prototype={howCool:function(){returnthis.name+"er";}};vara1=newA(),a2=newA();a1.name="hot";//li

javascript - 中级 JavaScript : assign a function with its parameter to a variable and execute later

我有一个JavaScript函数:functionalertMe($a){alert($a);}我可以这样执行:alertMe("Hello");我想做的是将带有"Hello"参数的alertMe("Hello")赋给一个变量$func,然后稍后可以通过执行$func();之类的操作来执行此操作。 最佳答案 我想添加评论作为答案代码//definethefunctionfunctionalertMe(a){//returnthewrappedfunctionreturnfunction(){alert(a);}}//declaret

Javascript/Jquery : Mathematically Divide Two Variables

这是我的代码:varframeWidth=400;varimageWidth=$('#inner-image').css('width');varnumberOfFrames=imageWidth/frameWidth;如何使“numberOfFrames”显示为商数?IE。将“frameWidth”和“imageWidth”处理为数字,而不是对象?如果我需要更清楚地解释自己,请告诉我。谢谢! 最佳答案 .css('width')可能返回带有px的值。您可以使用parseInt()只获取数字。varframeWidth=400;va

javascript - "$variable"和 "variable"之间有什么区别 - JavaScript - jQuery

我在jQuery的$(document).ready(function()下初始化了2个变量,var1和$var2。什么是这两个变量之间的主要区别(或可能的区别)?var1="var1";$var2="var2";$('#click1').click(function(){alert(var1);});$('#click2').click(function(){alert($var2);});Here是工作fiddle。 最佳答案 没有区别。Javascript允许在标识符中使用$字符,例如变量和函数名称,就像它允许使用字母、数字和

javascript/youtube api - undefined variable YT

我正在创建一个通过YTapi嵌入的YouTube播放器,但我不断收到一个警告,提示变量YT未定义。我可以看到包含了youtubeAPI的脚本,它应该创建变量YT-为什么这不起作用?它适用于我网站的其他地方。这是链接:http://oncreativity.tv/site/single/4/7CtQaTmEuWk和我的代码:$(document).ready(function(){vartag=document.createElement('script');tag.src="http://www.youtube.com/player_api";varfirstScriptTag=doc

javascript - Jquery each() : variable in callback always has last value?

似乎无法弄清楚这里发生了什么。DiscoverDocumentationDownloadDonate$('.navItem').each(function(){$link=$(this).children('a');$link.hover(function(){$link.css('width','224px');},function(){$link.css('width','192px');})});http://jsfiddle.net/Sth3Z/它应该为每个链接都这样做,而不是它只更改最后一个链接,无论将鼠标悬停在哪个链接上。 最佳答案