问题标签 [library-design]
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.
java - 为什么Java中的java.lang.Thread类没有被设计者标记为final?
当我们可以通过实现 Runnable 并将其传递给 Thread 构造函数来实现相同的功能时,允许用户通过扩展 Thread 类来创建线程的本质是什么。
regex - 为什么 RegexTest 有一个 main 方法?
我想知道为什么scala.util.parsing.combinator.testing.RegexTest有一个 main 方法。
库类不是打算从程序中调用而不是作为独立的可执行文件单独运行吗?
javascript - 返回自身实例的对象
背景:我最近的项目不能使用大型库,这让我很伤心。我想从任何库中获得一些东西,例如缺少的函数、、、addClass
兼容等。所以我创建了一个小对象,我想在其他时间发表一些意见,但我有一个设置它的方式有点麻烦。hasClass
removeClass
addEventListener
为了使用方便,我希望一个对象在创建时返回它自己的一个新实例。
鉴于:
我们得到 DOMWindow 而不是$
因为 JavaScript 的古怪性质this
。 对我来说更奇怪的是console.log(new $().name)
正确返回“列维”。如果this
绑定到窗口,为什么对象正确获取值?. 我们可以添加新的console.log(new $())
并且它可以工作。但是,我不想每次都写新的。所以我尝试了:
这给了我想要的东西,但是将对象包装在创建它的函数中似乎有点不必要。此外,返回的对象 isobj
和 not $
。比较测试会失败。
还有哪些其他方法可以做到这一点?有没有更优雅的解决方案?我毫不犹豫地重新思考我的整个过程。我认为自己非常擅长使用 JavaScript,但是创建新的 JavaScript 是我非常陌生的事情。
有人认为以下解决方案有什么问题吗?
它似乎在我所有的测试中都有效。
scala - 用于不可变的最终单例对象的 val 或对象
考虑到更改与源兼容,通常应该首选哪种解决方案?
这
或这个?
c++ - instantiating a free template function within a template class
I need to instantiate a free template function (FTF) within a template class (TC). The FTF takes as a template parameter one of the template parameters of the TC. The TC also holds generic pointers to these FTF's, and these functions are called through the pointers.
The step of taking a pointer to a FTF is not enough to instantiate it, and I receive linker errors from the GCC toolchain. MSDN illustrates FTF specification as so -- however my instantion of the FTF is dependant on a template parameter of my TC, and therefore the FTF instantiation cannot be placed in free scope.
Is this possible ? I am attaching some basic generated code, the issue is in the constructor of the class test_service
, where I assign the pointer of a free function into a custom container. I get a linker error telling me the free function cannot be found (uninstantiated). I know that specifying a call to the template function in the class somewhere will produce a instantiation, however I am only going to be making a call via a pointer.
EDIT: self-contained minimal version
network-programming - boost::asio 和 boost::bind 错误
这个问题有点烦人,我无法编译下面的代码。您必须编译下面的代码。
我在使用 boost asio 时遇到了一些问题,我试图将接受连接的逻辑抽象为一个统一的抽象,以便我可以使用常规 TCP/IP 统一启动 Windows 命名管道和 Unix 域套接字的连接。
下面的代码中显示了 3 个类,前 2 个是接受 TCP 连接的实现,下面的第三个类是根据前 2 个实现的泛型类。我在boost::bind
调用时遇到问题。问题可能在于我对语义的理解。
如果我创建TcpDestinationAcceptor::handle_accept
一个常规成员函数(即,不是模板成员函数),导致我没有传递AcceptHandler
参数。代码编译得很好。注意:我不会从TcpDestinationAcceptor::StartAccepting
.
注意:我已经开始了不同的设计,如果可能的话,我仍然想继续这个设计。
自包含代码:
xml - scala.Predef 中 $scope 的目的是什么?
scala.Predef
包含以下代码:
考虑到它创建了对可能很容易从标准库中拆分出来的包的依赖关系,有人弄清楚为什么有必要吗?
javascript - 为什么 jquery 链接回调中的“this”是一个 DOM 元素?
所以我知道在使用$.fn.each
,$.fn.bind
等时, this
jQuery 链接回调中的关键字是一个 DOM 元素是标准的。
我知道在我的开发中,至少我通常希望将 DOM 元素包装在一个 jQuery 集合中——90% 的时间我最终都会这样做var $this = $(this)
。我确信他们为什么选择绑定到展开的元素有一个很好的(可能是基于性能的)理由,但有人知道它到底是什么吗?
这是我觉得知道答案可能会打开更深层次理解库和语言的大门的事情之一。
delphi - 为什么 TStringList 有 BeginUpdate 和 EndUpdate?
我知道在 TListBox 等 VCL 控件上使用 BeginUpdate 和 EndUpdate 可以加快使用 Items 填充控件的过程,因为它可以防止控件被重新绘制,直到调用 EndUpdate。
例子:
上面会有延迟,因为允许重新绘制 Listbox,但是可以通过阻止重新绘制来缩短延迟,如下所示:
现在我使用 TStringList 对此进行了测试:
似乎无论 TStringList 是否使用 BegindUpdate 和 EndUpdate,列表的填充速度大致相同。
尽管 TStringList 是在内存中执行而不是在视觉上执行,但它们是否真的需要。无论如何,我是否应该在 TStringList 上使用 BeginUpdate 和 EndUpdate,这样做是一种好习惯吗?
问这个我觉得很傻,但为什么 TStringList 有 BeginUpdate 和 EndUpdate 程序?
我想我可能已经在这里回答了我自己的问题,无论哪种方式,我都想听听您的意见。
谢谢 :)