I see, but... How is this:
(function($) { $.something = function() { alert('something'); } $.test = { abc: function() { alert('test'); } } })(jQuery); Different from this: jQuery.something = function() { alert('something'); } jQuery.test = { abc: function() { alert('test'); } } Besides the syntax used of course. I mean, you simply do $.something() or $.test.abc() and it will work no matter if you coded in the first way or second... timothytoe wrote: > Any time you create a function without a name it's anonymous. Example: > > window.setTimeout(function() { alert('Hello world!') }, 60); > > On Feb 22, 4:56 pm, Nazgulled <[EMAIL PROTECTED]> wrote: > > timothytoe wrote: > > > The function doesn't have a name, so it doesn't pollute the namespace, > > > and it's great for making functions inline for handlers and > > > setTimeout() without the burden of having to make up a name that won't > > > even be referenced. > > > > Can you give me an example of what you mean? I'm getting a bit > > confused... > > > > > > > > > It's an outgrowth of everything being an object in JavaScript, and > > > being able to pass any object as a parameter. A function is an object > > > in JavaScript and can be passed as a parameter. > > > > Yes, I knew that, I just don't see how it relates to anonymous > > functions. > > > > > > > > > It's very powerful. > > > > > On Feb 22, 4:39 pm, Nazgulled <[EMAIL PROTECTED]> wrote: > > > > And what exactly it means to hide a function, making it anonymous? > > > > > > timothytoe wrote: > > > > > JavaScript has really expressive ways to call functions. The first > > > > > parentheses hide the function (make it anonymous) and the second > > > > > executes the code immediately with the parameter listed. I'm a newbie > > > > > myself, but I think that means "right now, pass the variable jQuery in > > > > > as $ to the function and execute the code." > > > > > > > On Feb 22, 4:06 pm, Nazgulled <[EMAIL PROTECTED]> wrote: > > > > > > Thanks... > > > > > > > > And what's up with the: > > > > > > > > (function($) { > > > > > > // CODE > > > > > > > > })(jQuery); > > > > > > > > This was the thing that got me most confused when reading the > > > > > > documentation. Can someone explain me this, what it does, what is > > > > > > for > > > > > > and the best scenarios where would I need to use something like > > > > > > this? > > > > > > If possible, explain me like I was really dumb :P > > > > > > > > Klaus Hartl wrote: > > > > > > > On Feb 23, 12:14�am, Nazgulled <[EMAIL PROTECTED]> wrote: > > > > > > > > Hi, > > > > > > > > Let's say I have 2 different javascript files. I like to > > > > > > > > organize my > > > > > > > > code that's why I use 2 different files so each file will only > > > > > > > > have > > > > > > > > functions that fall into that file's category. > > > > > > > > > > Anyway, here's the files layout... > > > > > > > > > > file1.js: > > > > > > > > function Fn1() { ... } > > > > > > > > function Fn2(a, b) { ...} > > > > > > > > > > file2.js > > > > > > > > function FnX(a, b, c) { ... } > > > > > > > > function FnY(a, b) { ... } > > > > > > > > function FnZ(a) { ... } > > > > > > > > > > How can I call those functions in a syntax like this: > > > > > > > > $.groupName.Fn1(); > > > > > > > > $.groupName.Fn2('text', 123); > > > > > > > > > > or > > > > > > > > > > jQuery.groupName.FnZ(true); > > > > > > > > > > How do I do this? > > > > > > > > > > P.S: I've read the plugins authoring documentation page but I'm > > > > > > > > still > > > > > > > > confused and I don't know how to achieve this, please advise... > > > > > > > > > Something like: > > > > > > > > > $.groupName = $.groupName || {}; > > > > > > > $.extend($.groupName, { > > > > > > > Fn1: function() { > > > > > > > ... > > > > > > > }, > > > > > > > Fn2: function(a, b) { > > > > > > > ... > > > > > > > } > > > > > > > }); > > > > > > > > > --Klaus