javascript - declare function properties inside -
i know can set function property below
function f(){} f['a']=1;//setting function property outside alert(f.a)//alert 1
but possible set property of function below or there other similar way of declaring properties inside function,rather outside?
function f() { a: 1 } alert(f.a); //get 1 output
edit:
looking way not use object creation function constructor or use prototypes
no, there not. inside function goes body, i.e. code executed when function called. function literal / declaration not object literal, if both use curly braces.
if you're looking more declarative way assignment put static properties on function, use kind of extend
functionality:
var f = object.assign(function f() {}, { a: 1 });
(all of _.extend
, $.extend
, object.assign
work purpose - otherwise use f.a =
)
Comments
Post a Comment