草庐IT

private-class

全部标签

javascript - 私有(private)函数和变量 ExtJs4?

在我当前的项目中,我使用的是ExtJs3.3。我创建了许多具有私有(private)变量和函数的类。例如:MyPanel=function(config){config=config||{};varbar='bar';//privatevariablefunctiongetBar(){//publicfunctionreturnbar;}functionfoo(){//privatefunction}Ext.apply(config,{title:'Panel',layout:'border',id:'myPanel',closable:'true',items:[]});MyPane

javascript - Javascript:Function和Class有什么区别

随着2015年6月ECMAScript6的发布,引入了Javascript类语法。这个语法:classPolygon{constructor(width,height){this.width=width;this.height=height;}}基本上与:functionPolygon(width,height){this.width=width;this.height=height;}那么,使用类而不是传统函数有什么好处?在什么情况下我应该使用类而不是函数? 最佳答案 类和函数之间有一些区别-大多数人会从说类是“只是语法糖”开始,

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 - 为什么要删除我的类(class)名称?

我正在学习Reactjs,我正在渲染一个包含一些组件的简单页面。其中一个组件是:classHeaderextendsReact.Component{render(){return();}}exportdefaultHeader我正在使用BootstrapCSS我希望header中的div使用container的样式,但是在构建之后,下课了。有没有办法强制组件中的属性类? 最佳答案 您必须使用className属性而不是class属性,例如:classHeaderextendsReact.Component{render(){retu

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 - ExtJS 3 : Two ways of creating custom class: what's the difference?

我正在努力学习ExtJS和面向对象的JavaScript。我见过人们以多种方式在自定义命名空间中定义类。这两种方法有什么区别?方法一Ext.ns('myapp.cars');(function(){varCar=Ext.extend(Object,{//...})myapp.cars.Car=Car;})()方法二Ext.ns('myapp.cars');myapp.cars.Car=Ext.extend(Object,{//...});方法二更易读,需要的代码更少;有什么理由方法1更好吗?谢谢! 最佳答案 基本相同,只是第一种方法

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 - 在 JavaScript 中覆盖 "private"函数

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

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