FANDOM


Static methods Edit

19:25 < simoncpu> hmmm... what's the difference between var moo = new Class({cow: function() {}});
19:25 < simoncpu> and moo.cow = function() {} ?
19:26 -!- Jwv_SaMY [n=jwv@ac-217-129-177-172.netvisao.pt] has joined #mootools
19:26 < Azra-el> thanks fakedarren :)
19:27 -!- Jwv [n=jwv@cdr03-84-91-8-198.netvisao.pt] has quit [No route to host]
19:27 < fakedarren> simoncpu: in the first example, 'moo' ends up being a mootools class, in the second, it's just a normal javascript object
19:28 < simoncpu> fakedarren: what if moo is already a mootools class? why do we need to define cow outside Class()?
19:28 < fakedarren> moo.implement({ cow: function() {}
19:29 < fakedarren> considering I'm at work, I don't really have time to explain that now, but if you read through stuff like the 'up the moo herd' blog posts they explain a lot about mootools classes
19:29 < simoncpu> ah...
19:29 < fakedarren> short answer: it gets loads of cool shit that native JS objects don't have
19:30 < simoncpu> i'm just curious why i can't access test() even though it has been defined via var Form.Validator = new Class({test: function() {}});
19:30 < simoncpu> but i can see the functions that were defined using Form.Validator.add = function() {}
19:30 < simoncpu> in firebug
19:31 < akaIDIOT> its the same diff as static and instance members in something like java
19:31 < akaIDIOT> works a bit different in JS, but the effect is similar
19:32 < akaIDIOT> inside Class({...}) = instance, myClass.method = static
19:32 < Bluebie> ...
19:32 -!- fabiomcosta [n=fabio@187.40.249.206] has joined #mootools
19:32 < simoncpu> aha, so i need to instantiate the class first before i can access test()?
19:32 < simoncpu> var wee = new Form.Validator()?
19:33 < akaIDIOT> then wee.test() ought to work
19:33 < simoncpu> aaaaaaah
19:33 < Bluebie> Factoid: Java, Javascript, as related as Ponies and Ponces!
19:33 < Bluebie> okay bad example
19:33 < simoncpu> suddenly, i feel so enlightened
19:33 < akaIDIOT> yea i know
19:33 < Bluebie> goodo <_<
19:33 < akaIDIOT> but java is something most ppl know
19:33 < simoncpu> btw, does javascript hava a notion of public/private methods?
19:33 < akaIDIOT> and it has static and non-static
19:34 < akaIDIOT> simoncpu: euhm, not _really_
19:34 -!- Rendez [n=Rendez@204.Red-79-148-241.staticIP.rima-tde.net] has joined #mootools
19:34 < simoncpu> akaIDIOT: i know that java and javascript are unrelated, but your explanation was very effective
19:34 < Bluebie> simoncpu: No.
19:34 < akaIDIOT> that was wat i was aiming at :P
19:34 < Bluebie> Javascript doesn't even have the notion of methods at all
19:35 < akaIDIOT> that notion is created by moo :)
19:35 < simoncpu> i really should read up about prototype-based languages
19:35 < Bluebie> it has closures/functions, which are assigned as properties of 'objects' which really more closely resemble a simple Hash structure
19:35 < simoncpu> ah... so objects are not really objects, but just hashes that are accessed in a way that resembles oop?
19:36 < akaIDIOT> the oop is something moo does
19:36 < simoncpu> ahhhh
19:36 < simoncpu> i see
19:36 < akaIDIOT> and moo has something alike private, but you should have a really weird reason to use that