nodejs stringformat包,没有方法格式
我安装nodejs stringformat pacakage,并运行他们的第一个示例: https ://npmjs.org/package/stringformat
但我得到以下错误:
> npm install stringformat > node > var $ = require('stringformat') > console.log($.format("Hello, {0}!", "World")) TypeError: Object function () { // Call as a method return format.apply(arguments[0], Array.prototype.slice.call(arguments, 1)) } has no method 'format' at repl:1:16 at REPLServer.self.eval (repl.js:110:21) at Interface.<anonymous> (repl.js:239:12) at Interface.EventEmitter.emit (events.js:95:17) at Interface._onLine (readline.js:202:10) at Interface._line (readline.js:531:8) at Interface._ttyWrite (readline.js:760:14) at ReadStream.onkeypress (readline.js:99:10) at ReadStream.EventEmitter.emit (events.js:98:17) at emitKey (readline.js:1095:12) >
可能是什么问题?
它没有format()
方法。
你可以使用它作为一个function:
console.log($("Hello, {0}!", "World"))
或者通过启用String
扩展:
$.extendString(); // here, you call format() on a String instance . console.log("Hello, {0}!".format("World"));