/java-script/

Obiekty w Javascript

2012-08-09 20:55:31


<script>
        // sposób pierwszy tworzenie obiektu
        var obj_1 = new Object();
        obj_1.name = &quot;blog&quot;;
        obj_1.url = &quot;blog.btbw.pl&quot;;

        var obj_2 = new Object();
        obj_2.name = &quot;google&quot;;
        obj_2.url = &quot;google.com&quot;;

        console.log(obj_1);
        console.log(obj_2);

        //sposób drugi tworzenie obiektu
        var Www = function(name,url){
            this.name = name;
            this.url = url;
        };

        var obj_3 = new Www('blog','blog.btbw.pl');
        var obj_4 = new Www('google','google.com');

        console.log(obj_3);
        console.log(obj_4);

        //dostęp do parametrów
        console.log(obj_1.name);
        console.log(obj_1[&quot;name&quot;]);

        // obiekt z parametrami i metodą
        var Blog = function(name,url){
            this.name = name;
            this.url = url;
            this.show = function(){
                console.log(this.name +' - '+this.url);
            };
        };

        var blog_3 = new Blog('btbw','blog.btbw.pl');
        blog_3.show();
</script>

jak to podsumować... noClass