草庐IT

object-properties

全部标签

javascript - jQuery 中的 "Uncaught TypeError: cannot read property ' 长度 ' of null"

我正在定义在我的HTML上按下按钮时发生的以下操作:$(document).ready(function(){$("#query").keydown(function(){//stuff$.get(url,function(result){console.log(result);varlist="";for(vari=0,l=result["results"].length;i'+result["results"][i]["label"]+'';}list="Herearesomeresults:"+list+"";});});到达“结果”的是一个JSON数组,格式如下:{"resul

javascript - Underscore.js _.isObject = function (obj) { return obj === Object(obj); };

当我们查看Underscore.js源码时,我们可以看到如下内容:_.isObject=function(obj){returnobj===Object(obj);};我知道它有效。但为什么不用这个:_.isObject=function(obj){returntypeofobj==="object";};? 最佳答案 不同之处在于棘手的值null。typeofnull返回'object',这显然很令人困惑,而不是想要的结果。但是,将对象构造函数与null一起使用会导致创建新对象(参见MDN)。这意味着您可以区分对象和null,这是

返回对象的javascript函数返回[object Object]

我的函数的预期输出是{"name":"bob","number":1},但它返回[objectObject]。我怎样才能达到预期的输出?functionmyfunc(){return{"name":"bob","number":1};}myfunc(); 最佳答案 哈哈这似乎是一个简单的误会。您正在返回对象,但是对象的toString()方法是[objectObject]并且它被freecodecamp控制台隐式调用。Object.prototype.toString()varo={};//oisanObjecto.toString

javascript - 为什么 Angular 5 Transition 抛出 AppComponent.html :2 ERROR TypeError: Cannot read property 'forEach' of undefined

为什么Angular5会抛出这个错误?AppComponent.html:2ERRORTypeError:Cannotreadproperty'forEach'ofundefined我正在研究Angular动画的概念验证,我直接使用网站上的代码。我的组件如下所示:import{Component,OnInit}from'@angular/core';import{trigger,state,style,transition,animate,keyframes}from'@angular/animations';@Component({selector:'app-obj-list',te

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

关闭。这个问题需要debuggingdetails.它目前不接受答案。编辑问题以包含desiredbehavior,aspecificproblemorerror,andtheshortestcodenecessarytoreproducetheproblem.这将有助于其他人回答问题。关闭4年前。Improvethisquestion升级到16.x后出现以下错误UncaughtTypeError:Cannotreadproperty'injection'ofundefinedatinjectTapEventPlugin(injectTapEventPlugin.js:23)ateva

javascript - 无论如何在 Visual Studio 智能感知中定义一个 undefined object ?

假设我在AngularJS中有一个Controller:myApp.controller('SearchController',function($scope,UserService){//forintellisense,UserServiceisundefinedherevaruser=UserService.getUsers().then(function(data){//yadayada},function(err){//yadayada});});但是,在我的intellisense文件中,我可以动态注入(inject)UserService来获取它的功能,如下所示:intel

javascript - JQuery JavaScript 设计 : Self Executing Function or Object Literal?

关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我很好奇在构造封装代码块时是否有任何与JQuery相关的最佳实践。通常,当我构建一个页面时,我喜欢将该页面中使用的函数封装在一个对象中。这允许我在构建应用程序时进行一些封装。没有什么比看到带有一堆这样的JavaScript文件更让我讨厌的了functiondoSomethingOnlyRelevantOnThisPage(){//dosomestuff}这会导致设计困惑,并且没有很好地封装

object - 编写一个 javascript 库

我想写一个JS库,然后这样处理:varc1=Module.Class();c1.init();varc1=Module.Class();c2.init();当然,c1和c2不能共享相同的变量。我想我知道如何处理对象,它是:varModule={Class={init=function(){...}}}但问题是如果我这样写,我不能有多个Class实例。所以我试图通过功能实现相同的目标,但我认为我做的不对。(function(){varModule;window.Module=Module={};functionClass(i){//Howcan"this"refertoClassinst

javascript - 类型错误 : Cannot read property 'Roboto-Regular.ttf' of undefined

尝试使用JSAPIPdfMake构建PDF:然后根据thisHelloworld,我跑:vardocDef={content:'ThisisansamplePDFprintedwithpdfMake'}pdfMake.createPdf(docDef).download('optionalName.pdf');我遇到了这个错误:UncaughtTypeError:Cannotreadproperty'Roboto-Regular.ttf'ofundefined是否需要Roboto-Regular.ttf文件?如果是,放在哪里? 最佳答案

javascript - 将函数调用保存到变量时为 "object is not a function"

我试图通过将函数缓存到变量来使我的代码更小。例如:functiontest(){vara=Array.prototype.slice,b=a.call(arguments);//DosomethingsetTimeout(function(){varc=a.call(arguments);//Dosomethingelse},200);}所以我可以不调用Array.prototype.slice.call(arguments),而是调用a.call(arguments);。我试图通过缓存Array.prototype.slice.call使它更小,但那不起作用。functiontest