问题标签 [private-members]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c# - 强制垃圾收集或反射到私有字段,哪个更不邪恶?
我们有一个第三方库,它在内部将 SafeHandle 用于非托管资源。在某些错误情况下,有必要处理对象并重新创建它。但是,在 dispose 实现中存在一个错误,该错误会阻止 Handle 在这些情况的子集中关闭。这会阻止新对象在其终结器运行之前成功创建。
已经提出了两种解决方案(都是邪恶的)来解决这个问题,直到我们可以修复第三方代码:
运行 a
GC.Collect
让终结器运行并清理对象如果 dispose 未能这样做,请使用反射获取 Handle 并关闭它
其中哪一个不那么邪恶,为什么?有没有其他我们没有考虑过的方法比这两种方法更邪恶?
java - How to automatically remove private fields and methods in Java classes
I have a code generator which generates classes with a lot of private code like:
I'm looking for a tool which would remove all unused private fields/methods and inner classes without human intervention. I would also like it to work on source code instead of byte code to be able to conduct metrics on the generated source code. Changing the code generator would be possible but I'm looking for something simpler.
javascript - MooTools 1.3+ 类中的私有属性
在过去的几天里,我一直在研究一种在 MooTools 类中拥有私有或受保护属性的方法。各种文章(即 Sean McArthur 的在 MooTools 类中获取私有变量)提供了一种用于 MooTools 已弃用版本的方法,但我无法找到 MooTools 1.3+ 的工作方法。
今天,在玩了几个小时的代码之后,我想我已经创建了一个合适的解决方案。我说“想想”,因为我真的没有作为程序员的经验。我希望这里的社区可以检查我的代码并告诉我它是否真的是一个有效的解决方案,或者一个 hackjob 仿真。
我真的很感激任何提示!感谢大家!
编辑:嗯,这很尴尬。我忘了检查显而易见的 obj1._data。我不认为this会引用实例对象!所以,我很烂。不过,任何想法都会很棒!
c# - C# 中的单元测试链式私有方法
我的问题是我的班级中有公共方法,它正在调用私有方法。私有方法正在调用另一个私有方法,依此类推,有 4 个链式私有方法。我知道我应该只为公共方法编写单元测试。就我而言,我将拥有完整的代码覆盖率,因为所有私有方法都是从公共方法调用的。但万一出现问题,我的单元测试将不知道究竟是哪种方法搞砸了。我知道我应该尝试将我的一些方法移动到单独的类中,以便我可以测试它们,但这意味着我应该创建 4 个不同的类,每个类中只有一个方法。
那么有没有办法测试这些私有方法中的每一个,或者我应该使用 Visual Studio 中的集成功能来测试私有方法?
java - 为什么在 Java 中将私有内部类成员设为公有?
如果仍然无法在包含类之外访问它,那么在 Java 中将私有内部类的成员声明为 public 的原因是什么?或者可以吗?
javascript - Unable to access members in javascript
I'm defining a class in javascript as
Here user can access Class.publicFunction, but not Class.privateFunction.
Now I want to provide the user an interface to extend this Class. So I added a public function extend.
My aim was to use the extend attribute as follows
and access it as
The problem I face is the call to the privateFunction() in the extended function someFunc is not available for it. I can understand that it is the problem of the scope, but, is there anyway to solve my need.
c++ - 类中具有与类本身相同类型的成员的“不完整类型”
我有一个类应该有同一个类的私有成员,例如:
但它告诉我 member 是不完整的类型。为什么?如果我使用指针,它不会告诉我不完整的类型,但我宁愿不使用指针。任何帮助表示赞赏
java - Java继承中的私有成员
有人告诉我,对于 Java 子类,它可以继承其超类的所有成员。那么这是否意味着即使是私人成员?我知道它可以继承受保护的成员。
谁可以给我解释一下这个。我现在完全糊涂了。
c# - 在 Silverlight 中访问私有成员
我对 Silverlight 很陌生,但我看到这一直在做。我只是还不知道该怎么做。
如何访问私人会员的功能?
首先,当一个单独的线程调用与 BusyIndicator 关联的窗口代码时,我在尝试使用 Busy Window Indicator 时遇到了运行时错误。
无论如何,所以我的解决方案是尽量让这个电话尽可能公开。但现在我得到一个编译错误。有人可以帮我弄这个吗?
请建议我如何克服此错误消息。