javascript - How to assign to members of a function? -
javascript - How to assign to members of a function? -
since functions first class objects, should possible assign members of them.
am right thinking arguments.callee
this?
are there other ways set these fields?
how possible set field
in first case?
function something1() { arguments.callee.field = 12; } alert(something1.field); // show undefined something1(); alert(something1.filed); // show 12 something2 = function() { arguments.callee.field = 12; }; alert(something2.field); // show undefined something2(); alert(something2.field); // show 12
update 1
i mean how access members within function when runs.
you don't need utilize arguments.callee
refer function has name; can utilize name. naturally case when declare function using the
function name(...) { ... }
syntax; in function expression, you're allowed supply temporary name:
(function temp_name(...) { ... })(arg);
so, if want set properties within function, can write:
function something1() { something1.field = 12; } alert(something1.field); // show undefined something1(); alert(something1.field); // show 12 something2 = function something2() { // note sec "something2" something2.field = 12; }; alert(something2.field); // show undefined something2(); alert(something2.field); // show 12
javascript arguments member first-class-functions
Comments
Post a Comment