问题标签 [singleton-methods]
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.
objective-c - 单例设计实现
根据我之前的问题,在这里,我已经调整了我的数据控制器类以使用单例设计模式,以便我只能在多个视图中使用它一次。但是我确实有几个问题,我似乎也找不到解决方案。
首先,我不确定如何在两个视图中调用类/对象以使其工作,其次,我已经使用 + 将初始化方法设为全局,但我需要对每个方法都这样做吗?
为了共享数据,我希望能够跨视图共享的类的初始化是
该类使用三个可变数组作为主要内容,需要在两个视图中设置和读取。
objective-c - Objective-C 宏 - 调用单例对象的方法
我正在使用单例对象/类,并且需要经常调用它的方法之一,并且需要从大型项目的许多地方调用。我需要定义一个宏来处理这个问题,但它目前不起作用。这也需要处理变量参数列表。这就是我为#define 所做的:
我也试过这个:
结果是如下所示的编译器错误。
作为旁注,这是我最近开始从事的一个现有项目,目前我不能过多地干预它的结构。将所有对“OldMethod”的调用替换为对新方法的调用或重写“OldMethod”会更容易,但我不能这样做。为什么?好吧,这很复杂,所以让我们假设我需要弄清楚如何为此使用宏......
谢谢!
ruby - 如何找到私有单例方法
我已经定义了一个Vehicle
这样的模块
调用Vehicle.singleton_methods
返回[:build]
。
如何检查由定义的所有私有单例方法Vehicle
?
java - concurrent calls of singleton class methods
I have a singleton class:
And multiple Threads are calling the work() function:
I noticed the two Threads are running concurrently, as if two work functions were instantiated at the same time.
I want the last thread to be run in place of the previous thread, rather then concurrently. Is it possible in java to make the second call override the memory space of the first call?
ruby - 定义单例方法
以下代码来自《Exceptional Ruby 》一书:
如果我注释掉分配新对象的第一行starts_with_a
,则会收到此错误:
问题1:为什么我需要分配一个新对象starts_with_a
来避免该错误?
此外,方法定义在之前starts_with_a
有一个,尽管变量没有。如果我在方法定义中省略了它,则会出现错误。.
===
starts_with_a
.
问题2:这是怎么.
回事?为什么有必要等等。
php - 将 phpUri 调用转换为 CI 库调用
本机 PHP 中的代码:
我在 CI 中尝试的代码不起作用:
您可以在此处查看 phpUri 本机库。我刚刚更改了类名 rest is same 的情况,使其在 CI 中工作。我在另一个库中使用它,所以使用 CI 实例。
ruby - 通过include添加类方法
我有 Ruby 类,我想在其中包含类和实例方法。按照此处描述的模式,我目前正在使用以下内容:
我宁愿不制作两个单独的模块(一个被包含,另一个被扩展),因为我模块中的所有方法在逻辑上都适合在一起。另一方面,这种模式 a) 要求我定义一个附加ClassMethods
模块,b) 要求我为每个模块编写一个样板self.included
方法。
有一个更好的方法吗?
编辑1:我找到了另一种方法,但我不确定这是否比第一种更好。
ruby - `Object#define_singleton_method(symbol, method)` 如何在 ruby 中工作?
来自Doc of define_singleton_method
我有两种语法来定义singleton
方法,如下所示:
define_singleton_method(symbol) { block } -> proc :
使用上面的语法,我尝试了下面的代码和我理解的语法:
但是需要有人帮助找出每个具有以下语法的示例。
定义单例方法(符号,方法)-> 新方法
根据文档 - 方法参数可以是 a Proc
、 aMethod
或UnboundMethod
对象。我在那里没有任何例子。
任何人都可以在这里帮我找到一个反对斜体字的例子吗?
ruby - Where does `singleton` methods reside in Ruby?
I was playing with singleton class
in my IRB. And doing so tried the below snippets.
Here above I just created a singleton
method on instance of class Foo
.
In the above I tried to create a singleton class
on instance of class Foo
. And also tested if foo_sing
holds reference to the singleton class
on instance of class Foo
.
In the above I was looking if singleton_method
bar
is in the foo_sing
or not.But found it is not present there.Then my question is - where does thosesingleton_method
reside in Ruby?
In the above part I was checking if we can create,instance of singleton class
or not and subclass of singleton class
,like regular class. But the answers I found as NO. What is the concept or theory or purpose behind it ?
Again in the following code I can see the that same name methods are being overridden inside a singleton class
. But when I am searching that method inside the class not found as I asked above.
ruby - Ruby 中的单例方法有任何例外吗?
在 Ruby 中,一切都是对象。但是,当我尝试对数字使用单例方法时,会出现类型错误。一切都是对象的概念有什么例外吗?