草庐IT

new_name

全部标签

javascript - 为什么 new Array(4).join ("ha") 产生 "hahahaha"而不是 "undefinedhaundefinedha .."

为什么newArray(4).join("ha")产生“hahaha”而不是“undefinedhaundefinedha..“?vararr=newArray(4);alert(arr[0]);//produces`undefined` 最佳答案 undefined或null的数组元素被转换为空字符串。It'srightthereinthedocumentation.Ifanelementisundefinedornull,itisconvertedtotheemptystring.

javascript - 谷歌分析 : _setvar to new tracking code

我一直在使用旧版本的分析代码,并使用以下代码来跟踪不同类型的用户try{varpageTracker=_gat._getTracker("UA-xxxxxxx");pageTracker._setVar('memberlevel-2');pageTracker._trackPageview();}catch(err){}如何将其与新的异步代码一起使用?GoogleAnalytics论坛已死,我没有收到任何回复:( 最佳答案 尝试阅读此设置自定义变量:http://code.google.com/apis/analytics/docs

javascript - 使用 Object.create 而不是 new 时传递参数

这个问题不是Using"Object.create"insteadof"new"的重复问题.有问题的线程在使用Object.create时没有专注于正确传递参数我很好奇如何使用Object.create而不是new来初始化对象。到目前为止,这是我的代码:functionHuman(eyes){this.eyes=eyes||false;}Human.prototype.hasEyes=function(){returnthis.eyes;}functionMale(name){this.name=name||"Noname";}Male.prototype=newHuman(true)

javascript - 为什么 new Date(undefined) 创建了一个无效日期,而 new Date(null) 却没有?

我今天发现Javascript有一些奇怪的地方:console.log(newDate(null));//1970-01-01T00:00:00.000Zconsole.log(newDate(undefined));//InvalidDate为什么会这样?我知道null和undefined不一样,但在这种情况下,我希望得到相同的结果。 最佳答案 如果调用newDate时使用了一个非字符串的原始参数,它将把它转换为一个数字。虽然null将强制转换为0,但undefined将变为NaN,这就是日期的内部值回来了。console.log

javascript - Firefox 权限 : 'name' member of PermissionDescriptor 'camera' is not a valid value for enumeration PermissionName

我正在制作一个网络应用,需要使用权限查询来检查是否已授予用户相机访问权限。我试过代码:navigator.permissions.query({name:'camera'}).then(function(result){console.log(result);});它在GoogleChrome70上运行良好,但在firefox上出现错误:TypeError:PermissionDescriptor“camera”的“name”成员不是枚举PermissionName的有效值。我一直在寻找这个问题,但没有任何帮助。有人能帮帮我吗?谢谢, 最佳答案

javascript - 从 RouteProvider 定义 ng-view ="NAME"

我真的是Angular的新手,我有一个关于将模板或URL发送到ng-view的小问题。但是我打算做的方式可能必须在我的基本模板中使用ng-view。当我的模板库是这样的时候:我的JS看起来像:varapp=angular.module('myApp',[]).config(['$routeProvider','$locationProvider','$httpProvider',function($routeProvider,$locationProvider,$httpProvider){$routeProvider.when('/home',{templateUrl:'/conta

使用 `new Function()` 优化 Javascript

在阅读文档时,我发现了一个可以大大提高javascript性能的简单优化。原代码:functionparseRow(columns,parser){varrow={};for(vari=0;i优化代码:varcode='return{\n';columns.forEach(function(column){code+='"'+column.name+'":'+'parser.readColumnValue(),\n';});code+='};\n';varparseRow=newFunction('columns','parser',code);在这里找到:https://github

javascript - "new DOMParser.parseFromString"能比 "createElement"更安全吗?

我创建了一个脚本来尝试删除不安全的内容(我将它用于浏览器扩展):varstr="Hellomundo";CreateDOM(str);functionRemoveAttrs(target){varattrs=target.attributes,currentAttr;varvalidAttrs=["href","class","id","target"];for(vari=attrs.length-1;i>=0;i--){currentAttr=attrs[i].name;if(attrs[i].specified&&validAttrs.indexOf(currentAttr)===

javascript - 未捕获的类型错误 : Cannot read property 'name' of undefined

单击“选择文件”时,我有以下代码:$(':file').change(function(){if(this.files.length==1){$('#selected_files').html("Attaching"+this.files.length+"file");}else{$('#selected_files').html("Attaching"+this.files.length+"files");}$('#selected_files').append("FilenameSize");for(x=0;x"+name+"("+filesize(size)+")"+type+"

javascript - 语法错误 : missing variable name

我在跑JavaScriptLint在一个项目上检查常见的编程错误。我遇到了这个错误:SyntaxError:missingvariablename在这一行:varchar,font;通过谷歌搜索,我发现将保留字用作变量名时会显示该错误;但根据MDN'slist判断,char和font均未保留。这里有什么问题? 最佳答案 没关系,我通过阅读找到了答案Whatisthe'char'keywordusedfor?.显然char在ECMA3中被保留,但在ECMA5中作为保留关键字被删除。我现在重命名了我的var,以防止旧实现产生任何潜在问题