草庐IT

private-methods

全部标签

javascript - 使用 ExtJS 扩展类时的私有(private)成员

我在ExtJS论坛上做了一些关于扩展类中的私有(private)方法和字段的研究,我找不到任何真正的答案。当我说扩展类时,我的意思是这样的:Ext.ux.MyExtendedClass=Ext.extend(Ext.util.Observable,{publicVar1:'Variablevisiblefromoutsidethisclass',constructor:function(config){this.addEvents("fired");this.listeners=config.listeners;},//toshowthatIneedtousethebaseclassp

javascript - 在揭示模块模式中公开私有(private)变量

我正在尝试实现RevealingModulePattern,但我无法公开修改后的私有(private)属性。varmyRevealingModule=(function(){varname='Diogo';functionsetName(){name=name+'Cardoso';}return{fullName:name,set:setName};}());//Sampleusage:myRevealingModule.set();console.log(myRevealingModule.fullName);//"Diogo"insteadoftheexcepted"DiogoCa

javascript - 从javascript类中的 "Public"方法访问 "Private"方法

有没有一种方法可以从类中的“私有(private)”函数调用“公共(public)”javascript函数?查看下面的类:functionClass(){this.publicMethod=function(){alert("hello");}privateMethod=function(){publicMethod();}this.test=function(){privateMethod();}}这是我运行的代码:varclass=newClass();class.test();Firebug给出了这个错误:publicMethod未定义:[出现此错误时中断]publicMeth

javascript - 这个错误 "Declaration of instance field not allowed after declaration of instance method."是什么意思

在我的Angular2项目中,我收到此错误:“在声明实例方法之后不允许声明实例字段。相反,这应该出现在类/接口(interface)的开头。(成员排序)”我想了解如何解决这个问题以及我为什么会遇到这个问题。错误与下一段代码中的私有(private)函数有关:exportclassHomeComponentimplementsOnInit{publicerror:string;publicshirts=[];constructor(publicrest:RestService,publicscService:ShoppingCartService,publicsnackBar:MdSna

javascript - 在 JavaScript 中覆盖 "private"函数

我正在修补一些jQuery的Draggable代码*。目标是避免修改原始源文件和动态修补内部功能之一。函数_generatePosition声明如下:(function($){$.widget("ui.draggable",$.ui.mouse,{..._generatePosition:function(event){...}}})(jQuery);是否可以实现动态替换呢?*因此它计算相对于父元素顶部的捕捉网格,而不是相对于被拖动元素的顶部。参见here了解更多详情。 最佳答案 您可以操作单个实例:.draggable().dat

javascript - 为什么我有这个错误 : Object doesn't support property or method 'forEach' for Internet Explorer?

我正在使用maven在jenkins插件上使用Javascript,我有以下代码:functionarrayElements(element,index,array){vararrayPaths=element.split("\\");varprojectSource=arrayPaths[2];vararray=element.split("_");if(projectSource===global){if(array[2]===filtro){document.getElementById("source").options.add(newOption(arrayPaths[3],

javascript - Angular 4 : Build to prod: Property is private and only accessible within class

我正在使用Angular4,我正在运行:ngbuild--prod我明白了:ngbuild--prodYourglobalAngularCLIversion(1.2.2)isgreaterthanyourlocalversion(1.0.0).ThelocalAngularCLIversionisused.Todisablethiswarninguse"ngset--globalwarnings.versionMismatch=false".Hash:7fce5d10c4c3ac9745e8Time:68351mschunk{0}polyfills.7790a64cc25c48ae62

javascript - javascript中的嵌套类,私有(private)方法的继承

我是javascript的新手,我花了一些时间尝试在js中创建命名空间对象。现在,这就是我想要做的:MainObject=function(){varprivateVariable="i'mprivate";varprivateMethod=function(){//doSomething}this.publicMethod=function(){//doPublicSomething}}MainObject.prototype.nested=function(){this.publicNestedMethod=function(){//that'snotworkingatallthi

Javascript从同一对象中的私有(private)方法调用公共(public)方法

我可以从私有(private)方法中调用公共(public)方法吗:varmyObject=function(){varp='privatevar';functionprivate_method1(){//canIcallpublicmethod"public_method1"fromthis(private_method1)oneandifyesHOW?}return{public_method1:function(){//dostuffhere}};}(); 最佳答案 做类似的事情:varmyObject=function(){

javascript - Firefox 异常 'JavaScript component does not have a method named: "可用"'

我正在使用Django构建网络应用程序。我通过Ajax(jQueryv1.8.3)在Javascript中调用了一堆API。它们中的大多数都有效,但有一个特定的结果会返回一个状态为0的对象,并将此消息作为状态文本:[异常...“'JavaScript组件没有名为:'available''调用方法时:[nsIInputStream::available]”nsresult:“0x80570030(NS_ERROR_XPC_JSOBJECT_HAS_NO_FUNCTION_NAMED)”location:“JSframe::http://127.0.0.1:8000/media/js/jq