【发布时间】:2013-05-25 21:26:15
【问题描述】:
我有一个覆盖 CoffeeScript 中主要类型的函数,但是这个函数返回值,我想改变自己。
String::replaceAll = (what, to) ->
regexPattern = new RegExp(what, "g")
this.replace regexPattern, to
现在我必须以这种方式使用它:
test = test.replaceAll "sth", "sth2"
我想以这种方式使用它:
test.replaceAll "sth", "sth2" # only, without assigning
(this = this.replace regexPattern, to # 不起作用)
【问题讨论】:
-
您为什么要这样做?为什么不接受它的工作原理?
-
代码少,不关心赋值。我有很多函数 ovverides 主要类型,我想以这种方式使用:“some string”.func().func1().func2()
-
但是默认函数可以链式,我不懂?
标签: javascript node.js express coffeescript