草庐IT

async_read

全部标签

Javascript Async=true 属性

我在某个未具名vendor的文档中看到此代码示例。它似乎异步加载脚本,然后从中调用函数。我意识到if-undefined检查可以防止明显的错误,但这不是完全不正确吗?我相信在IE8/9中它会正常工作,但会阻塞执行,直到加载并执行LOADER_URL脚本;而且我相信许多其他支持异步属性的浏览器,这只会导致内联block仅在部分时间执行ifblock内的代码。文档指出“标签是异步的,不会减慢页面的加载速度。”if(typeof(OBJECT_DEFINED_IN_LOADER_URL)!="undefined"){OBJECT_DEFINED_IN_LOADER_URL.Load(fals

javascript - 如何使用 async/await 将此回调转换为 promise?

以下函数从url获取图像,加载它,并返回它的宽度和高度:functiongetImageData(url){constimg=newImage()img.addEventListener('load',function(){return{width:this.naturalWidth,height:this.naturalHeight}})img.src=url}问题是,如果我这样做:ready(){console.log(getImageData(this.url))}我得到undefined因为函数运行但图像尚未加载。如何使用await/async只在图片加载完成且宽高已经可用时才

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

我正在使用nvd3绘制折线图,​​当我将div传递给nvd3绘制图表时,它给我这个错误UncaughtTypeError:Cannotreadproperty'createElementNS'ofundefined代码如下:varchartDiv='line-chart'+counter++;tmpl=$($('#charts-panel-template').clone().html());tmpl.find('.feature-line-chart').attr('id',chartDiv);vardiv=tmpl.find('.feature-line-chart#'+chart

javascript - 为 Angular JS 启用 html 5 模式会抛出 JS 错误 : Failed to instantiate module due to: TypeError: Cannot read property 'html5Mode' of undefined

如何为AngularJS启用html5模式?'usestrict'varblogApp=angular.module('blogApp',['ngRoute']).config(['$routeProvider',function($routeProvider,$locationProvider){$routeProvider.when('/disclaimer',{templateUrl:'templates/disclaimer.html',controller:'DisclaimerCtrl'});$routeProvider.otherwise({redirectTo:'/'}

javascript - require.js 未捕获类型错误 : cannot read property '__module_path__; of undefined

所以我刚刚开始尝试掌握require.js,但它似乎不起作用。当我使用标签将其包含在我的html中时:在chrome中加载页面时出现以下错误UncaughtTypeError:Cannotreadproperty'__MODULE_PATH__'ofundefined->require.js:538在firefox中我得到一个稍微不同的错误:TypeError:parentisundefined->require.js:538不知道我怎么会导致这个问题,因为它是require.js的全新安装,我的main.js中还没有代码。提前致谢 最佳答案

javascript - async/await 会阻塞事件循环吗?

这个问题在这里已经有了答案:Willasync/awaitblockathreadnode.js(6个答案)InJavaScript,doesusingawaitinsidealoopblocktheloop?(8个答案)关闭4年前。我正在阅读Don'tBlocktheEventLoop来自Node.js指南。有一句话说:YoushouldmakesureyouneverblocktheEventLoop.Inotherwords,eachofyourJavaScriptcallbacksshouldcompletequickly.Thisofcoursealsoappliestoyo

javascript - 未捕获的类型错误 : cannot read property 'innerHTML' of null

谁能解释一下这个错误是什么?UncaughtTypeError:cannotreadproperty'innerHTML'ofnull这是导致问题的行:varidPost=document.getElementById("status").innerHTML; 最佳答案 varidPost=document.getElementById("status").innerHTML;您的网页中不存在“状态”元素。因此document.getElementById("status")返回null。虽然您不能使用NULL的innerHTML属

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

此问题在我的页面加载时发生。使用以下脚本-jquery.simplemodal-1.4.3.js-jqueryv1.7.1下面是一个小代码快照,是发生此错误的simplemodal内的代码。focus:function(pos){vars=this,p=pos&&$.inArray(pos,['first','last'])!==-1?pos:'first';//focusondialogorthefirstvisible/enabledinputelementvarinput=$(':input:enabled:visible:'+p,s.d.wrap);setTimeout(fun

javascript - Typescript "Cannot assign to property, because it is a constant or read-only"即使属性未标记为只读

我有以下代码typeSetupProps={defaults:string;}exportclassSetupextendsReact.Component{constructor(props:any){super(props);this.props.defaults="Whatever";}尝试运行此代码时,TS编译器返回以下错误:Cannotassignto'defaults'becauseitisaconstantoraread-onlyproperty.deafualts是只读属性,但显然没有这样标记。 最佳答案 您正在扩展R

javascript - 在 karma 中使用 angular.mock.inject 给出 "TypeError: Cannot read property ' $injector' of null"

我正在尝试使用Karma对AngularJS进行一些基本的单元测试。我编写的所有测试在语法上似乎都是正确的。但是我在最基本的步骤中遇到了问题,即代码的beforeEach部分。当我尝试运行测试时,出现以下问题TypeError:Cannotreadproperty'$injector'ofnullatObject.workFn(http://localhost:9876/absolute/Users/vesriram/Documents/AngularJS%20project/vendor/js/angular-mocks.js:1698:15)atObject.(http://loc