javascript - what does function () {} mean when assigned to a variable -
i know functions objects in javascript, , functions can assigned variables. aware of question: how (function() {})() construct work , why people use it?.
but know precisely mean in context: https://github.com/zsolt/retwis-nodejs/blob/master/domain.js#l43
user = function(){}
this line followed declaration of member functions (methods?) of "supposed" user
object. seems there no other explanation answer here in so.
it means user
function takes no inputs, has no side effects , returns nothing.
most class constructor , methods added later. user.foo = function() { /* ... */}
imply static method, more utilities class if you're used thinking in java architecture.
you should pseudo-classical inheritance in javascript. analogizing java, code adding static methods user
class, not object.
i'm still pretty convinced code following java class patterns because writer prefer user
constructor can instantiated, has static methods, , has no instance methods (that saw), on object properties functions. right circuitous, it's writer if java developer. have advantage instance methods may added user
later little client-code impact see no evidence happen user
(i didn't long).
by way, deduced because capitalizednames
functions implies should called new
in javascript engineering in general, implies it's class. figuring out why class might preferable has java experience.
Comments
Post a Comment