javascript - Function call with additional sub functions -
i'm asking myself if it's possible call function in js, while having additional subfunction inside it
fn(s); fn.subfn(s);
for example make utils this
var s = "123"; string(s) // true string.blank(s) // false
i think it's possible this:
function string(s) { if(s) return typeof(s) === "string"; return { blank: function(s) { return s.trim().length === 0; } } }
but every time call string(s) i'm redefining blank fn, possible poor performances , poor code, or i'm wrong?
thanks.
functions objects, yes, can add properties them:
function string(s) { return typeof(s) === "string"; } string.blank = function(s) { return s.trim().length === 0; }
this allow make calls
string(s); string.blank(s);
just shown in example.
comments code:
the function defined returns object when call string
, require call function
string().blank(s);
which different form example showed @ beginning.
Comments
Post a Comment