草庐IT

function-prototypes

全部标签

javascript - Chrome 扩展 js : Sharing functions between background. js 和 popup.js

假设我有一个JavaScript函数foo(),我想在后台和popup.html中执行它。例如:它每小时在我的Chrome扩展程序的后台执行一次,但也可以由用户通过单击按钮从弹出菜单(popup.html)激活。我目前有一个定义foo()的global.js脚本,当我在我的中包含对foo()的调用时>popup.js文件,它们可以毫无问题地执行。(如果我在popup.html中包含这两个脚本)但是,当我尝试访问background.js中的foo()时,调用不会执行(即使global.js包含在“后台”“manifest.json”扩展文件中:"background":{"persis

Javascript 在 Child 中调用 Parent 构造函数(原型(prototype)继承) - 它是如何工作的?

我知道它有效,但我不知道为什么以及如何。机制是什么?//ParentconstructorfunctionParent(name){this.name=name||"Thenamepropertyisempty";}//ChildconstructorfunctionChild(name){this.name=name;}//Originaly,theChild"inherit"everythingfromtheParent,alsothenameproperty,butinthiscase//IshadowingthatwiththenamepropertyintheChildcon

javascript - Angular 1.5 组件 : passing a function

是否可以将函数传递给组件并在传递参数的组件内部调用此函数?例子:帖子列表getPostUrl是一个函数(在容器Controller中):constgetPostUrl=(postId)=>{constprotocol=$location.protocol();consthost=$location.host();constport=$location.port();returnprotocol+"://"+host+""+(port!==80?":"+port:"")+"/blog/post/"+postId;};帖子列表:组件constPostList={"bindings":{"p

javascript - 我所有的 Observables 错误 'takeUntil is not a function'

出于某种原因,我无法在我的任何可观察对象上使用takeUntil方法。我的IDE(VisualStudioCode)在我编码时将其显示为有效方法,并且编译良好(从typescript),但是当我运行它时,我得到takeUntilisnotafunction在我的任何observables上。我使用的是rxjs版本5.3.0。我可以通过多种方式实现它,但这可能是最直接的:letsubject:BehaviorSubject=newBehaviorSubject({});letunsubscribe:Subject=newSubject();subject.takeUntil(unsubs

javascript - 创建一个 jQuery 插件 : best practices regarding functions' visibility?

我正在创建一个jQuery插件。到目前为止它工作正常,但我对我做事的方式有疑问:jQuery.fn.myMethod=function(){returnthis.each(function(){MyScope.doSomething(jQuery(this).attr("id"));});};varMyScope={//ThefunctionscontainedinMyScopeareextremelylinkedtothelogic//ofthispluginanditwouldn'tmakealotofsensetoextractthemdoSomething:function(i

javascript - React JS 未捕获引用错误 : function not defined

我正在尝试在ReactJs组件中发生单击事件时调用shuffleCards。但是,我收到以下错误:UncaughtReferenceError:shuffleCardsisnotdefined这是我的代码:constructor(props){super(props);this.state={count:0};}shuffleCards(array){vari=array.length,j=0,temp;while(i--){j=Math.floor(Math.random()*(i+1));temp=array[i];array[i]=array[j];array[j]=temp;}

javascript - JavaScript 中的 var thing 和 function thing() 有什么区别?

我只是想知道以下JavaScript对象声明之间的区别。具体来说,thingobjectliteral和thingclass中的thing1object之间的区别。代码:varthing={sanity:0,init:function(){//code},send:function(){//code}}functionthing(){this.sanity=0;this.init=function(){//code};this.send=function(){//code};}thing1=newthing(); 最佳答案 静态对象

javascript - Javascript 中的 !function 是什么意思?

这个问题在这里已经有了答案:Whatdoestheexclamationmarkdobeforethefunction?(8个答案)关闭5年前。很抱歉发布这个,但是!function无法通过google搜索,而且我没有在我的JavaScript代码中找到它。Twitter是这样使用它的:Tweet!function(d,s,id){varjs,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/wi

javascript - 使用类和原型(prototype)编写 jQuery 插件

以这种方式(使用类和原型(prototype))编写插件是好是坏,这种代码的缺点是什么?functionPluginName(jqueryObject,options){}PluginName.prototype={publicMethod:function(){},_privateMethod:function(){}}//InitializingvarmyPluginInstance=newPluginName($(".mySelector"),{myOption:1});myPluginInstance.publicMethod(); 最佳答案

javascript - 可重用的 javascript 对象、原型(prototype)和范围

MyGlobalObject;functionTheFunctionICanUseRightAwaySingleForAllInstansesAndWithoutInstanse(){function(){alert('NOCONSTRUCTORWASCALLED');}};长命名函数必须可从MyGlobalObject调用,这反过来必须在脚本加载后始终作为全局变量(到window)可用。它应该支持符合最新标准的可扩展性。我处于如何为应用程序构建JS基础的架构困境(几乎100%JS)。我们需要一个对象,即window.MyObject(像一个模块,像jQuery)所以它可以用VAR1v