问题标签 [method-names]

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.

0 投票
3 回答
999 浏览

javascript - Get a function name like printed in Chrome console

Considering this code :

Chrome prints o.f {} into the console. Do you know how this o.f part is called? More importantly, is there any way to get this result without using the console? I'd like to extract the name of a method from the function itself, that is to say, without any additional information.

I already know how to get the name in this case :

But it does not behave the same way in the situation described above.


The following content is mostly copied from comments.

I wanted to know if there is a "technical" word to talk about this o.f pattern, let's say for example "namespace", "identifier", or "function path". Then, I was wondering if there was a way to retrieve this information from a loaded script in a webpage. The following question may help you in understanding my goal, the paragraph which is right after the first code block is quite close to my idea : Does Chrome retain each object's constructor?.

Maybe I should have mentioned that my original goal was to generate a documentation at runtime :/ Something like a reflection API would have been helpful in this case. More precisely, I was looking for a way to include the name of a method into the decompilated form of the function. Look :

Class.prototype.method + '' gives function(){}. I'd like to inject the method's name to get this result : function method(){}.

The problem is that I don't have any information about which function I'm currently serializing since the operation occurs when the user clicks a link. I know I could easily store the name somewhere, binding the data to the anchor element for example, that's obvious to me, I was just curious to know if there was a way to retrieve this data the same way as Chrome.

0 投票
3 回答
272 浏览

java - 创建具有新实例的列表的方法的命名

有一种方法可以从一些参数创建一个新实例列表。我会这样称呼它:

但我也经常看到它以这样的方式命名:

我现在的问题是:每个创建(或更一般地说:返回)某些东西的方法是否应该以前缀get命名?

0 投票
3 回答
15196 浏览

java - 方法名称在 Java 的 log4j 记录器中未正确打印

我的日志发生在getParam()方法中。但它被记录为main方法。而且我有三个对象,但我没有看到关于哪个对象正在记录的任何信息。我也想要那个信息。

这是输出:

这是代码:

我的 log4j.properties:

在不同的注释:如果我没有注释上面的注释行并且最后一行注释掉了,我得到

它给出了正在记录的正确行号(19),但不是正确的方法。

0 投票
2 回答
122 浏览

ruby-on-rails - 在 rails 方法名称中使用 @ 符号

我有什么方法可以在 rails 方法名称中使用“@”符号吗?例如

Rails 似乎不喜欢它。

我想这样做以遵守一些外部约定(rails 之外)。

0 投票
1 回答
945 浏览

android - RemoteViews 方法名称

我正在创建一个使用一些小部件的应用程序,并使用setInt()remoteView 上的方法来更改背景源。这不是问题,但我想知道有关方法名称的文档在哪里。在 RemoteViews API 中,没有记录哪些方法名称是有效的并且可以使用。我读了很多关于这方面的文章,但每个人都只是说,并非所有方法都可用。但是我怎么知道支持哪种方法呢?是否有任何进一步的链接或描述或 RemoteViews 的列表,我可以使用哪个方法名称?

它与 RemoteView 中的所有其他方法相同setBoolean()setDouble()等等。我还研究了 Android 的反射,但即使在这里也没有记录。

stackoverflow 中的所有问题似乎都只是处理一个特定的问题,但没有关于所有可用方法的答案(或者我真的必须是盲目的)。

0 投票
1 回答
82 浏览

swift - Swift 与 Objective-C 中的命名方法

全部:

在 Objective-C 中,名称是通过连接签名关键字来构造的,例如,application:didFinishLaunchingWithOptions:

在与其他程序员(包括学生)讨论时,人们如何引用 Swift 中的等效方法?例如,您会口头上将其称为application(), 还是application(_ didFinishLaunchingWithOptions:)?

谢谢,

迈克尔

0 投票
1 回答
1439 浏览

java - 为什么我得到“onCreate(Bundle) 已经定义”?

我正在尝试生成几个打开不同链接的按钮,但是通过复制文件,我得到一个错误,说 onCreate(Bundle) 已经定义了吗?是因为我有两个protected void onCreate(Bundle savedInstanceState) {还是什么?请添加对问题的描述以及可能的答案。

0 投票
0 回答
125 浏览

c# - 获取异常方法名

在 C#(特别是 MVC 5)中,如何获取发生异常的方法的名称?

这是我当前的代码:

我也试过:

在上述两个代码示例中,方法名称都报告为“MoveNext”。

谢谢

0 投票
1 回答
647 浏览

java - Java,通过反射记录的方法名称

研究快速日志记录实用程序方法。通常我会为此使用 Aspects,但在不支持该功能的 Android SDK 中工作。

我将如何使用反射以通用方式获取方法名称?

还有反射在java中的任何性能吗?

0 投票
2 回答
197 浏览

java - 一参数方法命名:方法名称中重复参数

有时我们需要创建一个只有一个参数的简单方法。例如:

所以,我的问题是:命名方法不是更好吗:isMocked(Player player) 而不是多次重复单词“Player”?有官方指导吗?我意识到这种重复对于二传手来说是必不可少的,但对于上述其他情况则不确定。

编辑:嗯,一个例子可能不是最好的。但问题不是关于这段代码片段,而是关于一般原则 - 我们是否应该在方法名称中重复参数类型?