I'm sorry. I did understand what you wrote but I was not really replying to it.
Calling goog.array.map with undefined is wrong. I agree that it is confusing that it iterates over the window. Adding runtime checks for invalid usage is something we have policy against. It adds to the code size as well as to the runtime cost.
On May 16, 2010 3:26 AM, "artemy tregubenko" <m...@arty.name> wrote:
Thank you for your reply, but it looks like I've failed to explain my
problem.
The following example is quite close to the real code I have. I do not
call goog.array.map(window, fun). I do not call
goog.array.map(undefined, fun). I have an object `foo`, containing
array as its property `bar`. My code iterates over this array:
goog.array.map(foo.bar, fun). Sometimes object doesn't have that
property `bar`, like object `baz` here. Since there's no array and
there're no elements of array, I expect code not to do anything.
However code calls `foo(window)`. This is the problem.
var foo = {bar: []}, baz = {};
var f = function(param){ console.log(param) };
goog.array.map(foo.ba...
This problem appears at runtime and thus cannot be solved by
compiler. I propose to replace
with
return goog.array.ARRAY_PROTOTYPE_.map.call(arr, f, opt_obj);
return !arr ? [] : goog.array.ARRAY_PROTOTYPE_.map.call(arr, f,
opt_obj);
On May 16, 11:09 am, Erik Arvidsson <erik.arvids...@gmail.com> wrote:
> Calling goog.array.map(win...
> On Fri, May 14, 2010 at 04:37, artemy tregubenko <m...@arty.name> wrote:
> > Hello,
>
> > I've jus...
Thank you for your reply, but it looks like I've failed to explain my
problem.
The following example is quite close to the real code I have. I do not
call goog.array.map(window, fun). I do not call
goog.array.map(undefined, fun). I have an object `foo`, containing
array as its property `bar`. My code iterates over this array:
goog.array.map(foo.bar, fun). Sometimes object doesn't have that
property `bar`, like object `baz` here. Since there's no array and
there're no elements of array, I expect code not to do anything.
However code calls `foo(window)`. This is the problem.
var foo = {bar: []}, baz = {};
var f = function(param){ console.log(param) };
goog.array.map(foo.bar, f); // does nothing
goog.array.map(baz.bar, f); // prints `[object Window]`