0

I have a code like this in javascript:

var func = function(){
    console.log('hello moto');
};
func.another = function(){
    console.log('another method outside function');
};

func();          // output: hello moto
func.another()   // output: another method outside function

I still don't know how to call this one. But I would like to use some method sticking into function name like that. I am wondering about the capability of this method on all browser. I test with Chrome + Safari + Firefox (all current version). It worked pretty well.

Does that code work well on all major browsers? Thanks!

Henry Tao
  • 1,076
  • 10
  • 14
  • 2
    Functions are first class *objects* in JavaScript, so you are basically augmenting an object and that is perfectly fine in JS. – thefourtheye Mar 11 '14 at 06:23
  • Advice about what? Your code works fine. – Shomz Mar 11 '14 at 06:24
  • OK! Cool. Thank @thefourtheye and Shomz. Javascript is different with other programming languages. So, in this case, I would like to make sure it work perfect on all major browsers. Thanks in advance. – Henry Tao Mar 11 '14 at 06:27
  • 2
    That's totally EcmaScript compliant and cross browser. – nembleton Mar 11 '14 at 06:39
  • are you asking [How to properly create a custom object (and methods) in Javascript?](http://stackoverflow.com/questions/1595611/how-to-properly-create-a-custom-object-in-javascript/1598077#1598077) – Paul Mar 11 '14 at 06:45
  • Thank @Paul. That's exactly what I want to ask. – Henry Tao Mar 11 '14 at 08:29
  • Well, that was asked and has a pretty good answer if you click the link. – Paul Mar 11 '14 at 08:30

0 Answers0