问题标签 [function-reference]

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 投票
1 回答
98 浏览

python - 以 Python 类方法为多态函数

编辑:这个问题基于两个错误:最初没有包含self在方法中,并且假设无界方法不会表现出多态性,但它们会表现出多态性。我投票关闭它。

我可以将一个方法作为 Python 中的函数值对象:

产生Hi, I'm A.foo.

到现在为止还挺好。但是,f不适用于子类:

仍然产生Hi, I'm A.foo,而b.foo()产生Hi, I'm B.foo。换句话说,多态性不适用。

问题:有没有办法随时获取函数值f对象?f(x) == x.foo()isinstance(x, A)

换句话说,我如何完成下面的代码片段才能正常工作?

0 投票
2 回答
83 浏览

c++ - 是否可以将函数引用保留到 unordered_map 或向量中?

我正在制作一些回调系统,我想知道我是否可以保留函数引用,unordered_map以便以后可以调用它。

是否可以使用这种类型的容器来保留回调函数?如果不是,它是使用函数指针的唯一方法吗?

0 投票
2 回答
44 浏览

kotlin - 将 Suspended-function 引用作为另一个函数参数传递

我创建了一个函数,它应该获取一个挂起的函数作为它的参数,运行它,并对结果执行一些操作。

当我尝试调用此函数并传递来自不同类的函数引用时(例如,我们称其为“SomeClass”),我在 intellij 上看到以下错误:

我的函数应该获得一个挂起的函数作为参数:

我从“OtherClass”引用的函数

对我的函数的调用,将OtherClass::performSomeOperation函数引用作为参数传递

0 投票
2 回答
69 浏览

c++ - Passing References to Member Functions

I've been working with a doubly-threaded BST in C++, and I thought it would be cool to separate my visitor functions from my various traversals. However I can't figure out how to properly pass references to member functions into my traversal functions. Here is a massively simplified version of my problem:

The problem of course comes in the traverse(&print); statement.

Any clues what's going wrong, or what I could try differently to achieve the same effect?