Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ClojureScript中的Fluent接口_Clojure_Clojurescript - Fatal编程技术网

ClojureScript中的Fluent接口

ClojureScript中的Fluent接口,clojure,clojurescript,Clojure,Clojurescript,我正在用ClojureScript编写一个库,它将公开一个公共JavaScript API。由于它必须模仿现有JavaScript库的API,因此我想介绍相同类型的fluent API: myLib.prepareToDo() .something() .and('also') .somethingElse() .run(function(err, result) { console.log("yay!"); }); 在Javascri

我正在用ClojureScript编写一个库,它将公开一个公共JavaScript API。由于它必须模仿现有JavaScript库的API,因此我想介绍相同类型的fluent API:

myLib.prepareToDo()
     .something()
     .and('also')
     .somethingElse()
     .run(function(err, result) {
         console.log("yay!");
});
在Javascript中,可以创建如下流畅的API):

我可以这样称呼它:

var obj = new MyClass(5);
obj.foo(1).foo(2).foo(3);
现在,据我所知,ClojureScript中没有
这个
的概念,尽管很显然可以将它作为访问

我不知道如何使用它,因此我的问题

如何在ClojureScript中创建一个流畅的界面?

(defrecord)
,并进行救援。将“magic”协议
Object
扩展到我们的记录或类型会导致定义的方法在JavaScript对象中显示为成员函数。为了启用“fluent接口”,一些方法返回
MyClass
的实例

(defrecord MyClass [a b]
    Object
      (something [this] this)
      (and-then [this s] (assoc this :a s))
      (something-else [this] (assoc this :b (str a "-" a)))
      (run [this f] (f a b)))
然后我们可以有一个JavaScript客户端,如下所示:

var myClass = new my_namespace.core.MyClass();
myClass.something()
   .and_then("bar")
   .something_else()
   .run(function(a, b) { 
       console.log(a + " - " + b) });
(defrecord)
和救援。将“magic”协议
Object
扩展到我们的记录或类型会导致定义的方法在JavaScript对象中显示为成员函数。为了启用“fluent接口”,一些方法返回
MyClass
的实例

(defrecord MyClass [a b]
    Object
      (something [this] this)
      (and-then [this s] (assoc this :a s))
      (something-else [this] (assoc this :b (str a "-" a)))
      (run [this f] (f a b)))
然后我们可以有一个JavaScript客户端,如下所示:

var myClass = new my_namespace.core.MyClass();
myClass.something()
   .and_then("bar")
   .something_else()
   .run(function(a, b) { 
       console.log(a + " - " + b) });
(defrecord)
和救援。将“magic”协议
Object
扩展到我们的记录或类型会导致定义的方法在JavaScript对象中显示为成员函数。为了启用“fluent接口”,一些方法返回
MyClass
的实例

(defrecord MyClass [a b]
    Object
      (something [this] this)
      (and-then [this s] (assoc this :a s))
      (something-else [this] (assoc this :b (str a "-" a)))
      (run [this f] (f a b)))
然后我们可以有一个JavaScript客户端,如下所示:

var myClass = new my_namespace.core.MyClass();
myClass.something()
   .and_then("bar")
   .something_else()
   .run(function(a, b) { 
       console.log(a + " - " + b) });
(defrecord)
和救援。将“magic”协议
Object
扩展到我们的记录或类型会导致定义的方法在JavaScript对象中显示为成员函数。为了启用“fluent接口”,一些方法返回
MyClass
的实例

(defrecord MyClass [a b]
    Object
      (something [this] this)
      (and-then [this s] (assoc this :a s))
      (something-else [this] (assoc this :b (str a "-" a)))
      (run [this f] (f a b)))
然后我们可以有一个JavaScript客户端,如下所示:

var myClass = new my_namespace.core.MyClass();
myClass.something()
   .and_then("bar")
   .something_else()
   .run(function(a, b) { 
       console.log(a + " - " + b) });