On Apr 8, 2:03 am, Geuintoo <drummerb...@gmail.com> wrote:
> Hy
>
> (function($){
>
>         $.myPlugin = function(){
>
>              holla: function(){
>                 alert('holla');
>             }
>         }

The above will create a myPluggin property of the object referenced by
$ (which is the jQuery object).  It assigns a reference to an
anonymous function, the body of which consists of the label:

  holla:

and the anonymous function:

  function(){ alert('holla'); }

The function does not do anything -  the internal anonymous function
is never called, nor does it return any value.  It is the equivalent
of an empty function object.


>         $.myPlugin.hello = function(){
>           alert('hello von Plugin');
>         }

The above creates a hello property of $.myPlugin and assigns a
reference to an anonymous function.  The body displays an alert with
some text.

>
> })(jQuery);
>
> // Works finde:
> $.myPlugin.hello();

Where "works" means displays the text "hello von Plugin".


> // It does not work. Why?
> $.myPlugin.holla();

Where "does not work" likely means throws an error as $.myPlugin does
not have a holla property, so trying to call it is doomed to failure.


> Is there a posibility to write a method in:
>
> ... snip
> $.myPlugin = function(){
>
>              // Write methode here
>             }
>         }
> ...snip
>
> So that
>   $.myPlugin.holla();
> will work?

There are many ways - what you seem to have attempted was an object
literal, so:

(function($) {
    $.myPlugin = {
        holla: function(){
            alert('holla');
        },
        hello: function(){
            alert('hello von Plugin');
        }
    }
})(jQuery);


--
Rob

Reply via email to