Forums > Javascript

Redefine post(), why doesn't this work?

November 25, 2013 | 12:08 am

In an attempt to create a post function that appends a newline at every call, I came up with this:

var global = this;
var __post = post;

var post = function(){
var args =, 0);
__post.apply(global, args.concat(‘\n’));

This doesn’t work. It generates the following error:
Javascript TypeError: __post is undefined, line 12

It does work as long as you use a different name for the post function, like this:

var log = function(){
var args =, 0);
__post.apply(global, args.concat(‘\n’));

Looks like it’s not really that __post is undefined, but that the assigned reference to post becomes undefined.

Just out of curiosity, why won’t this work?

Viewing 1 post (of 1 total)