The function sayHello() is defined inside the function jQuery.example,
and is thus an "inner function" or "nested function".  It exists only
when jQuery.example is executing.  It cannot be accessed from outside
jQuery.example without doing some magic with closures.

When you tried to override sayHello by setting
jQuery.example.sayHello, you created a new property "sayHello" on the
jQuery.example object.  You can use this same technique to define this
inner function the first time:


        jQuery.example = function(name) {
                jQuery.example.sayHello(name);
        };
        jQuery.example.sayHello = function(str) {
                console.log("jQuery.example.sayHello: " + str);
        };

You can then override sayHello with the exact code you used above:

        jQuery.example.sayHello = function(str) {
                alert("jQuery.example.sayHello(Overrided): " + str);
        };

This is probably the easiest solution.  Let me know if this doesn't
answer your question.

David

On Mar 3, 2:50 am, howa <[EMAIL PROTECTED]> wrote:
> Consider I have a simple plugin, e.g.
>
> jQuery.example = function(name) {
>
>         sayHello = function(str) {
>             alert("jQuery.example.sayHello: " + str);
>         };
>
>     sayHello(name);
>
> };
>
> at sometime later, I would want to override the original sayHello
> method(), so I add,
>
> jQuery.example.sayHello = function(str) {
>          alert("jQuery.example.sayHello(Overrided): " + str);
>
> };
>
> But this does not work.
>
> Any idea?
>
> Thanks.

Reply via email to