From 1470dc414d688e43240ace5dd345c582b08a7e5d Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Thu, 11 Nov 2010 12:09:50 -0800 Subject: [PATCH] s/sys.puts/console.log/ and add sprintf alias --- format.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/format.js b/format.js index c79ab4e..fc588e6 100644 --- a/format.js +++ b/format.js @@ -6,32 +6,27 @@ // ISC license // -var sys = require('sys'); - -function $args(args) { - return Array.prototype.slice.call(args); -} - exports.extendNativeStrings = function() { String.prototype.printf = function(/* ... */) { - var args = $args(arguments); + var args = [].slice.call(arguments); if (args[0] !== this) args.unshift(this); - sys.puts(exports.format.apply(this, args)); + console.log(exports.format.apply(this, args)); }; String.prototype.format = function(/* ... */) { - var args = $args(arguments); + var args = [].slice.call(arguments); if (args[0] !== this) args.unshift(this); return exports.format.apply(this, args); }; }; exports.printf = function(/* ... */) { - sys.puts(exports.format.apply(this, arguments)); + console.log(exports.format.apply(this, arguments)); }; +exports.sprintf = exports.format exports.format = function(format) { var argIndex = 1 // skip initial format argument - , args = $args(arguments) + , args = [].slice.call(arguments) , i = 0 , n = format.length , result = ''