[xwiki-devs] [Proposal]JavaScript console.log wrapper for our convenience
Hi devs, I'd like to commit a console.log wrapper in xwiki.js that does some checking before logging, in the spirit of http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/ Something like : var XWiki = { //snip /** * console#log wrapper for your developer own convenience */ log: function(){ if(typeof console != "undefined"){ console.log( Array.prototype.slice.call(arguments) ); } }, // snip } WDYT ? Jerome
+1, but out of curiosity.. On 10/28/2010 08:34 PM, Jerome Velociter wrote:
Hi devs,
I'd like to commit a console.log wrapper in xwiki.js that does some checking before logging, in the spirit of http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
Something like :
var XWiki = {
//snip
/** * console#log wrapper for your developer own convenience */ log: function(){ if(typeof console != "undefined"){
console.log( Array.prototype.slice.call(arguments) );
What's the point of Array.prototype.slice.call(arguments) ? Thanks, Marius
} },
// snip
}
WDYT ?
Jerome _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
On Fri, Oct 29, 2010 at 10:02 AM, Marius Dumitru Florea <[email protected]> wrote:
+1, but out of curiosity..
On 10/28/2010 08:34 PM, Jerome Velociter wrote:
Hi devs,
I'd like to commit a console.log wrapper in xwiki.js that does some checking before logging, in the spirit of http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
Something like :
var XWiki = {
//snip
/** * console#log wrapper for your developer own convenience */ log: function(){ if(typeof console != "undefined"){
console.log( Array.prototype.slice.call(arguments) );
What's the point of Array.prototype.slice.call(arguments) ?
Apparently it's a trick to transform the "arguments" array-like object into an array. See hhttps://developer.mozilla.org/en/JavaScript/Reference/Functions_and_function... I'm not sure what are the exact limitations of logging an array-like object versus a real array. In firebug, a visible difference is that you can expand the array as a whole (you have that little "+" on the left and then have all array properties and methods) , whereas with an array-like object you only see it's individual elements (that you can expand as well, individually), but can't expand the array. Jerome.
Thanks, Marius
} },
// snip
}
WDYT ?
Jerome _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
On 10/29/2010 12:09 PM, Jerome Velociter wrote:
On Fri, Oct 29, 2010 at 10:02 AM, Marius Dumitru Florea <[email protected]> wrote:
+1, but out of curiosity..
On 10/28/2010 08:34 PM, Jerome Velociter wrote:
Hi devs,
I'd like to commit a console.log wrapper in xwiki.js that does some checking before logging, in the spirit of http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
Something like :
var XWiki = {
//snip
/** * console#log wrapper for your developer own convenience */ log: function(){ if(typeof console != "undefined"){
console.log( Array.prototype.slice.call(arguments) );
What's the point of Array.prototype.slice.call(arguments) ?
Apparently it's a trick to transform the "arguments" array-like object into an array. See
hhttps://developer.mozilla.org/en/JavaScript/Reference/Functions_and_function...
I wasn't aware of this. It's clear now.
I'm not sure what are the exact limitations of logging an array-like object versus a real array. In firebug, a visible difference is that you can expand the array as a whole (you have that little "+" on the left and then have all array properties and methods) , whereas with an array-like object you only see it's individual elements (that you can expand as well, individually), but can't expand the array.
Thanks, Marius
Jerome.
Thanks, Marius
} },
// snip
}
WDYT ?
Jerome _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
Why not simply defining console and console.log() when it is undefined ? This would avoid the need to think about using a specific wrapper. WDYT ? Denis On Fri, Oct 29, 2010 at 13:42, Marius Dumitru Florea < [email protected]> wrote:
On 10/29/2010 12:09 PM, Jerome Velociter wrote:
On Fri, Oct 29, 2010 at 10:02 AM, Marius Dumitru Florea <[email protected]> wrote:
+1, but out of curiosity..
On 10/28/2010 08:34 PM, Jerome Velociter wrote:
Hi devs,
I'd like to commit a console.log wrapper in xwiki.js that does some checking before logging, in the spirit of http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
Something like :
var XWiki = {
//snip
/** * console#log wrapper for your developer own convenience */ log: function(){ if(typeof console != "undefined"){
console.log( Array.prototype.slice.call(arguments) );
What's the point of Array.prototype.slice.call(arguments) ?
Apparently it's a trick to transform the "arguments" array-like object into an array. See
hhttps:// developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope/arguments
I wasn't aware of this. It's clear now.
I'm not sure what are the exact limitations of logging an array-like object versus a real array. In firebug, a visible difference is that you can expand the array as a whole (you have that little "+" on the left and then have all array properties and methods) , whereas with an array-like object you only see it's individual elements (that you can expand as well, individually), but can't expand the array.
Thanks, Marius
Jerome.
Thanks, Marius
} },
// snip
}
WDYT ?
Jerome _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Denis Gervalle SOFTEC sa - CEO eGuilde sarl - CTO
That would work, but there is a drawback in this approach too : what do we define exactly ? If we define console.log, maybe developers will expect console.warn to be defined as well, and start using it without checks. And maybe console.profile, next. The problem is there is no standard cross-browser API ( - or I could not find it), so it will be hard to draw the line of what we allow and what we don't. If we define our own API, then it's clear. Jerome. On Fri, Oct 29, 2010 at 5:54 PM, Denis Gervalle <[email protected]> wrote:
Why not simply defining console and console.log() when it is undefined ? This would avoid the need to think about using a specific wrapper. WDYT ?
Denis
On Fri, Oct 29, 2010 at 13:42, Marius Dumitru Florea < [email protected]> wrote:
On 10/29/2010 12:09 PM, Jerome Velociter wrote:
On Fri, Oct 29, 2010 at 10:02 AM, Marius Dumitru Florea <[email protected]> wrote:
+1, but out of curiosity..
On 10/28/2010 08:34 PM, Jerome Velociter wrote:
Hi devs,
I'd like to commit a console.log wrapper in xwiki.js that does some checking before logging, in the spirit of http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
Something like :
var XWiki = {
//snip
/** * console#log wrapper for your developer own convenience */ log: function(){ if(typeof console != "undefined"){
console.log( Array.prototype.slice.call(arguments) );
What's the point of Array.prototype.slice.call(arguments) ?
Apparently it's a trick to transform the "arguments" array-like object into an array. See
hhttps:// developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope/arguments
I wasn't aware of this. It's clear now.
I'm not sure what are the exact limitations of logging an array-like object versus a real array. In firebug, a visible difference is that you can expand the array as a whole (you have that little "+" on the left and then have all array properties and methods) , whereas with an array-like object you only see it's individual elements (that you can expand as well, individually), but can't expand the array.
Thanks, Marius
Jerome.
Thanks, Marius
} },
// snip
}
WDYT ?
Jerome _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Denis Gervalle SOFTEC sa - CEO eGuilde sarl - CTO _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
On Fri, Oct 29, 2010 at 18:12, Jerome Velociter <[email protected]> wrote:
That would work, but there is a drawback in this approach too : what do we define exactly ? If we define console.log, maybe developers will expect console.warn to be defined as well, and start using it without checks. And maybe console.profile, next. The problem is there is no standard cross-browser API ( - or I could not find it), so it will be hard to draw the line of what we allow and what we don't. If we define our own API, then it's clear.
Well, it depends what you really want, but building a specific API does not help when you want to integrate existing libraries or helps new contributors. The firebug API has became a de-facto standard for logging and is starting to be implemented natively in many browsers. So, if you want to be really light, as suggested at the start of this thread, just do this: http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/ If you want a full featured solution, go a little bit further but do not reinvent the wheel: http://benalman.com/projects/javascript-debug-console-log/ These approaches provides for me the best solution for the lowest price, and use a well known API that every Javascript developer knows. I completely disagree that having a specific API is clearer, since you need to learn one more stuff. I am almost -1 for building such API. I am +1 for any of the above evolutive solution. Denis
Jerome.
On Fri, Oct 29, 2010 at 5:54 PM, Denis Gervalle <[email protected]> wrote:
Why not simply defining console and console.log() when it is undefined ? This would avoid the need to think about using a specific wrapper. WDYT ?
Denis
On Fri, Oct 29, 2010 at 13:42, Marius Dumitru Florea < [email protected]> wrote:
On 10/29/2010 12:09 PM, Jerome Velociter wrote:
On Fri, Oct 29, 2010 at 10:02 AM, Marius Dumitru Florea <[email protected]> wrote:
+1, but out of curiosity..
On 10/28/2010 08:34 PM, Jerome Velociter wrote:
Hi devs,
I'd like to commit a console.log wrapper in xwiki.js that does some checking before logging, in the spirit of http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
Something like :
var XWiki = {
//snip
/** * console#log wrapper for your developer own convenience */ log: function(){ if(typeof console != "undefined"){
console.log( Array.prototype.slice.call(arguments) );
What's the point of Array.prototype.slice.call(arguments) ?
Apparently it's a trick to transform the "arguments" array-like object into an array. See
hhttps://
developer.mozilla.org/en/JavaScript/Reference/Functions_and_function_scope/arguments
I wasn't aware of this. It's clear now.
I'm not sure what are the exact limitations of logging an array-like object versus a real array. In firebug, a visible difference is that you can expand the array as a whole (you have that little "+" on the left and then have all array properties and methods) , whereas with an array-like object you only see it's individual elements (that you can expand as well, individually), but can't expand the array.
Thanks, Marius
Jerome.
Thanks, Marius
} },
// snip
}
WDYT ?
Jerome _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Denis Gervalle SOFTEC sa - CEO eGuilde sarl - CTO _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
-- Denis Gervalle SOFTEC sa - CEO eGuilde sarl - CTO
participants (4)
-
Denis Gervalle -
Jerome Velociter -
Jerome Velociter -
Marius Dumitru Florea