Drycodez Posted September 9, 2011 Share Posted September 9, 2011 Is it possible for an array to hold a function? E.g: A=new Array()A[0]="property"A[1]=function(var1){alert(var1)} Link to comment Share on other sites More sharing options...
Ingolme Posted September 9, 2011 Share Posted September 9, 2011 Yes. Link to comment Share on other sites More sharing options...
Drycodez Posted September 9, 2011 Author Share Posted September 9, 2011 But why is it that people dont use it? I hardLy find it in scripts. Link to comment Share on other sites More sharing options...
justsomeguy Posted September 9, 2011 Share Posted September 9, 2011 There's usually not a reason. The main way people use functions like that is to assign them to objects and make them methods: var obj = { a: 'some value', b: 10, func1: function() { alert(this.a); }};obj.func1(); The only time you would really put functions in an array is if you need to call multiple functions and you loop through the array to call each one, like a series of event handlers or something. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.