草庐IT

this_is_not_a_task

全部标签

javascript - 我什么时候应该使用 `this.x` 与 `var x` ?

在创建JavaScript类函数时,我使用了this。很多。但是在使用它时,我想知道使用var是否会有所不同。varMyClass=function(){this.x=4;return{getVal:this.x};}与var的使用对比:varMyClass=function(){varx=4;return{getVal:x};}有什么区别,什么时候应该使用哪个?同样的问题适用于class语法:classMyClass{constructor(){constx=4;}}对比classMyClass{constructor(){this.x=4;}} 最佳答案

javascript - 网络音频 API : noteOn after noteOff not working?

我使用WebAudioAPI编写了一个简单的Web应用程序,但我注意到当我向给定源发出noteOn(0)命令,然后是noteOff(0),然后最后通过另一个noteOn(0)命令,声音将打开、关闭(如预期的那样),但随后不会通过第三个命令打开。我做错了什么吗?就这么简单,我可以给你看代码,但我觉得它是多余的。也许我需要在noteOff之后将缓冲区重新分配给源,但我无法想象它是如何使用的。 最佳答案 AudioBufferSourceNode只能播放一次。http://youtu.be/hFsCG7v9Y4c?t=18m22s

javascript - 为什么 jquery 不是 :not() selector working as I expect it to?

我正在尝试设置一个事件,该事件在单击没有.four类的任何内容时触发。但是,当单击带有.four类的内容时它会触发,即使我使用的是e.stopPropagation()。$("html").one("click",":not(.four)",function(e){e.stopPropagation();console.log("Somethingwithoutclass'four'wasclickedthathadclass:"+$(e.srcElement).attr("class"));});(jsFiddleDemo)这也不起作用:$("html").not('.four').

c# - WebBrowser 在 ObjectForScripting 上声明 "object type is not visible to COM"

我正在尝试使用WPFWebBrowser控件在C#和JavaScript之间建立互操作。到目前为止,C#->JavaScript调用运行良好,但我无法运行JavaScript->C#。我已经为对象创建了一个类:[ComVisible(true)]classBrowserClient{privateMainWindowowner;publicstringid="browser-client";publicBrowserClient(MainWindowowner){this.owner=owner;}publicvoidsendMessage(stringdate){owner.OnRe

javascript - Uncaught ReferenceError : $scope is not defined

加载页面时收到错误。我正在尝试将一个新对象附加到条目数组。代码有什么问题?index.html抽奖员{{entry.name}}抽奖.jsangular.module('myApp',[]).controller("RaffleCtrl",function($scope){$scope.entries=[{name:"Larry"},{name:"Curly"},{name:"Moe"}]});$scope.addEntry=function(){$scope.entries($scope.newEntry)$scope.newEntry={}}; 最佳答案

javascript - .css ('display' ) 是 block ,[0].hidden 是假的,.is (':hidden' ) 是真的吗?

我遇到了一个div被隐藏的情况,即使我刚刚执行了显示具有相同后缀的所有其他div的代码:$("[id$='-input-container']").show()尽管如此,一个特定的div仍然隐藏:$("#single-colorRange-color-input-container")。我想也许它被隐藏在代码后面的某个地方但没有-在调用$inputContainers.show()之后我立即添加了如下日志记录(和debugger语句停止所有后续执行):console.log($("#single-colorRange-color-input-container").css('displ

javascript - Angular2 Material Design alpha.9-3 有 '404 not found' @angular/material

我已按照angularmaterial2入门中的说明安装@angular/material。通过Atom,我更新了package.json、app.module,除了入门说明之外,我还更新了systemjs.config,如下所示:'@angular/material':'node_modules/@angular/material',我收到这些错误:zone.js:1274GEThttp://localhost:3000/node_modules/@angular/material/404(未找到)(SystemJS)XHR错误(404未找到)加载http://localhost:3

javascript - 为什么 (function() { return this; }).call ('string literal' ) 返回 [String : 'string literal' ] instead of 'string literal' ?

这是我在试验JS时的最新发现:(function(){returnthis;}).call('stringliteral');//=>[String:'stringliteral']inV8//=>String{"stringliteral"}inFF我在执行以下操作时偶然发现了这一点:(function(){returnthis==='stringliteral';}).call('stringliteral');//=>false谁能告诉我为什么函数内部的this不是作为第一个参数传递给call的正是?编辑1Whatisthedifferencebetweenstringprimi

javascript - 避免 IE 抛出 : Error: 'console' is undefined 的常见习语

我已经安装了firebug并编写了所有这些日志语句。我已经在IE中测试了我的应用程序,当然我遇到了“未定义”错误。避免这种情况的常用习语是什么。我真的不想评论我文件中的所有console.log语句,也不想mock它们。我不知道该怎么做。 最佳答案 我通常会像这样制作一个包装函数:functionlog(obj){if(window.console&&console.log)console.log(obj);}或者您可以在脚本文件/元素的开头执行类似的操作:if(!window.console){window.console={lo

javascript构造函数重置: What is it?

我看到这张幻灯片:http://www.slideshare.net/stoyan/javascript-patterns#postComment第35页:选项5+super+构造函数重置functioninherit(C,P){varF=function(){};F.prototype=P.prototype;C.prototype=newF();C.uber=P.prototype;C.prototype.constructor=C;//WHY???}我不明白。谁能解释一下最后一行是什么?C.prototype.constructor=C;//WHY???谢谢