jimfog Posted July 14, 2011 Share Posted July 14, 2011 My question is the following:Does it have any importance the ordering of the code when we are talking about a function definition and subsequently itsallocation to an object as a method?I mean, is there a difference between defining the function FIRST, then allocating it to an object as method in comparison with defining the object FIRST and then writing the function second?Does the ordering of the code plays a role in javascript when we are dealing with functions and objects? Link to comment Share on other sites More sharing options...
thescientist Posted July 14, 2011 Share Posted July 14, 2011 should be pretty easy to test, no? var Logger = function(text){ console.log(text);};var myObj = { log : Logger};myObj.log("test text"); vs. var myObj = { log : Logger};var Logger = function(text){ console.log(text);};myObj.log("test text"); vs. var myObj = { log : Logger};function Logger(text){ console.log(text);};myObj.log("test text"); edit: added JSG 'test'right? Link to comment Share on other sites More sharing options...
justsomeguy Posted July 14, 2011 Share Posted July 14, 2011 It depends on the syntax you use. In the syntax above it matters because the function is being declared as a variable. If you define the function like this then it doesn't matter where you define it: function test() { ... } Link to comment Share on other sites More sharing options...
thescientist Posted July 14, 2011 Share Posted July 14, 2011 that was my next test.... :)edited above... Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.