javascript - JS: Is it possible "something(arg)" and "something.my_method(arg)" at same time -
i know how create function something(arg)
something = function(arg) { console.log('function result', arg); }
i know how create object function something.my_method(arg)
something = { my_method: function(arg) { console.log('method result', arg); } }
is possible write code, wher both something(arg)
, something.my_method(arg)
exists?
like this
in file:
// needed code something(123) something.my_method(234)
output in console:
function result 123 function result 234
well, javacript, , there many ways it.
edit: thought this, , tried imagine other way same thing, , cannot find any. there's @elcodedocle thought close not ask, or otherwise other solution rewrite or 1 suggest below.
the quick , dirty way create function:
something = function(arg) { console.log('function result', arg); }
and create property holds other function:
something.my_method = function(arg) { console.log('method result', arg); }
though i'd have warn if need such thing else pure intellectual , academical curiosity, might want rethink design of code. kind of "trick" never elegant , misleading future code readers (which can you in 6 months).
Comments
Post a Comment