[英]ClojureScript + momentjs (node.js) fails with .format(“dddd, MMMM Do YYYY, h:mm:ss a”)
I'm trying to show current datetime format to console on node.js + clojure deploying momentjs . 我试图在node.js + clojure部署momentjs上显示当前日期时间格式。
The working node js code: 工作节点js代码:
var moment = require("./lib/moment/moment.js");
console.log(moment().format("dddd, MMMM Do YYYY, h:mm:ss a"));
Console output: 控制台输出:
$ node app1
Friday, July 5th 2013, 9:57:07 am
so, I tried a clojureScript code as below: 所以,我尝试了如下的clojureScript代码:
(ns rxcljs.core
(:use [cljs.nodejs :only [require]])
)
(def log #(.log js/console %))
(def moment (require "./lib/moment/moment.js"))
(->> (-> (moment)
(.format "dddd, MMMM Do YYYY, h:mm:ss a")
)
(log)
)
The Console output becomes 控制台输出变为
$ node app
FridaynullundefinedJulyundefined5thundefined2013nullundefined9null56null31undefinedam
Datetime is partially presented with bunch of null and undefined for some reason. 由于某种原因,日期时间部分呈现为一堆null和undefined 。
Compiled js code: 编译的js代码:
var rxcljs = {core:{}};
rxcljs.core.log = function(a) {
return console.log(a)
};
rxcljs.core.moment = cljs.nodejs.require.call(null, "./lib/moment/moment.js");
rxcljs.core.log.call(null, rxcljs.core.moment.call(null).format("dddd, MMMM Do YYYY, h:mm:ss a"));
The point the problem occurred looks not that problematic: 问题发生的重点看起来没有问题:
rxcljs.core.moment.call(null).format("dddd, MMMM Do YYYY, h:mm:ss a")
Any idea? 任何想法? Thanks.
谢谢。
This is due to a known incompatibility of Moment.js 2.0.0 with ClojureScript, fixed in this commit by David Altenburg . 这是由于Moment.js 2.0.0与ClojureScript的已知不兼容性,由David Altenburg在此提交中修复。 Here's the commit message:
这是提交消息:
Format function now uses "instanceof" on a var rather than "typeof" on that var's call to determine if the variable is a function.
格式函数现在在var上使用“instanceof”而不是var的调用上的“typeof”来确定变量是否是函数。
This fixes an incompatibility with ClojureScript, which defines String.prototype.call as a function.
这修复了与ClojureScript的不兼容性,ClojureScript将String.prototype.call定义为函数。
The version currently in the develop branch works fine. 当前在开发分支中的版本工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.