Új hozzászólás Aktív témák

  • Speeedfire

    félisten

    A könyv végén azért ott van, amit kerestem. :D

    var namespace = namespace || {};

    // here a namespace object is passed as a function
    // parameter, where we assign public methods and
    // properties to it
    (function( o ){
    o.foo = "foo";
    o.bar = function(){
    return "bar";
    };
    })( namespace );

    console.log( namespace );

    ;(function ( namespace, undefined ) {

    // private properties
    var foo = "foo",
    bar = "bar";

    // public methods and properties
    namespace.foobar = "foobar";

    namespace.say = function ( msg ) {
    speak( msg );
    };

    namespace.sayHello = function () {
    namespace.say( "hello world" );
    };

    // private method
    function speak(msg) {
    console.log( "You said: " + msg );
    };

    // check to evaluate whether "namespace" exists in the
    // global namespace - if not, assign window.namespace an
    // object literal

    })( window.namespace = window.namespace || {} );

Új hozzászólás Aktív témák