Jump to content

function ordering related to objets


jimfog
 Share

Recommended Posts

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

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?

Edited by thescientist
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...