草庐IT

sd_class

全部标签

javascript - Node.js 事件发射器 : How to bind a class context to the event listener and then remove this listener

有没有办法在事件监听器方法中访问类上下文并有可能删除监听器?示例1:import{EventEmitter}from"events";exportdefaultclassEventsExample1{privateemitter:EventEmitter;constructor(privatetext:string){this.emitter=newEventEmitter();this.emitter.addListener("test",this.handleTestEvent);this.emitter.emit("test");}publicdispose(){this.emi

javascript - "Class extends value #<Object> is not a constructor or null"

感谢阅读我的文章我的代码出现此错误:“Classextendsvalue#isnotaconstructorornull”这是我的代码,我正在尝试导出/导入类。怪物.js:constminiMonster=require("./minimonster.js");classmonster{constructor(options={name},health){this.options=options;this.health=100;this.heal=()=>{return(this.health+=10);};}}letbigMonster=newmonster("Godzilla");

javascript - angularjs ng-class 方法被多次调用

在这个例子中,我有2个ng-class,每个调用不同的Controller方法,由于某种原因每个方法被调用3次,知道吗?可能的错误?varnavList=angular.module('navList',[]);navList.controller('navCtrl',['$scope','$location',function($scope,$location){$scope.firstClass=function(){console.log('firstClass');return'labellabel-success';};$scope.secondClass=function(

javascript - 删除 :active pseudo-class from an element

我希望能够告诉一个元素它不再是:active以便CSS规则不再适用。有没有办法在JavaScript中做到这一点? 最佳答案 可能的解决方案:1)使用类:JS:document.getElementById("element").classList.remove("hasactive");CSS:#element.hasactive:active{background:blue;}2)阻止默认的mousedown功能(事件状态):编辑:显然,这只适用于Firefox。JS:document.getElementById("eleme

javascript - 除了 First Class Functions 和 Lexical Scoping,JavaScript 与 Scheme 实现有什么共同之处?

我一直想知道为什么DouglasCrockford总是将JavaScript与Scheme进行比较。是的,JS的设计者打算成为Scheme;但是除了一流的函数支持和词法作用域(已损坏)之外,JS与Scheme有哪些共同点使其成为“披着C外衣的Lisp”? 最佳答案 我想到的另一件事是在整个语言和库中普遍使用单一无处不在的数据结构:conslists在Scheme的情况下,maps(在ECMAScript中称为对象。不仅ECMAScript具有一流的过程这一事实,而且这些过程是唯一的抽象机制。(或者更准确地说是封装机制。)

JavaScript "classes"

在这种模式下使用JavaScript“类”有什么缺点吗?varFooClass=function(){varprivate="aprivatevariable";this.public="apublicvariable";varprivatefn=function(){...};this.publicfn=function(){...};};varfoo=newFooClass();foo.public="bar";foo.publicfn(); 最佳答案 你在你的例子中做的不是人们在JS中想到的“类”模式——通常人们会想到更“正常

javascript - 在 Bootstrap 日期选择器中将类(class)添加到多个/特定日期?

我很难在Bootstrap中向日期添加类。这是日期选择器。我想要实现的是在我指定的日期放置一个小蓝点。我正在考虑为日期添加一个类。我应该怎么做? 最佳答案 根据您使用的日期选择器,您可以执行如下操作:大多数日期选择器都有一个beforeShowDay选项。您可以在此处设置一个类(class)以添加到您要更改的日期。对于这个例子,我使用http://eternicode.github.io/bootstrap-datepicker如何执行此操作的示例可在此处找到:jsFiddle您需要将要突出显示/标记的日期放入数组中:varacti

javascript - 激活元素的 :active CSS pseudo-class using Javascript?

这可能吗?例如,如果用户按下“return”键并且我触发了“mousedown”事件,我该如何渲染带有:active样式的元素?我知道可以使用类来做到这一点,但我更愿意使用预先存在的:active样式。 最佳答案 根据CSS2.1spec,:active伪类适用于:anelementisbeingactivatedbytheuser.Forexample,betweenthetimestheuserpressesthemousebuttonandreleasesit.您应该能够以主题元素作为事件目标来调度mousedown事件,并且

javascript - 如何根据 Class 而不是 Id 进行 Google 音译

我正在做一个基于泰米尔语的Web应用程序。在我的应用程序中,我使用动态字段来添加用户详细信息。那么,动态字段有多个ID如何做到这一点或如何使用基于类的Google音译?//LoadtheGoogleTransliterationAPIgoogle.load("elements","1",{packages:"transliteration"});functiononLoad(){varoptions={sourceLanguage:'en',destinationLanguage:'ta',shortcutKey:'ctrl+m',transliterationEnabled:true

JavaScript 'class' 和单例问题

我有一个使用另一个对象(不是单例)的单例对象,需要一些信息给服务器:varsingleton=(function(){/*_privateproperties*/varmyRequestManager=newRequestManager(params,//callbacksfunction(){previewRender(response);},function(){previewError();});/*_publicmethods*/return{/*makearequest*/previewRequest:function(request){myRequestManager.re