????JavaScript???????????????????????????????????????????prototype??

????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

????????ж????????????????д???????????д??


<script type="text/javascript">            function load() {
                    function obj1() {//????obj1
                    }
                    function obj2() {//????obj2
                    }
                    obj2.prototype = new obj1(); //obj1?????obj2?????
                    Object.prototype.foo = function () {
                            alert("object"); //Object????foo????????object
                    }
                    testobj = new obj2(); //obj2????????????testobj
                    testobj.foo(); //??в???????foo????
                    obj1.prototype.foo = function () {
                            alert("obj1"); //??obj1????????foo??????
                    }
                    testobj.foo(); //?????в???????foo????
            }
            window.onload = load;
</script>


???????н????

?????????????

??????????????????obj1??obj2????obj1?????????obj2????Object?????????????foo???‘Object’?????obj2????????????testobj?????testobj?е?foo??????????????е???Object?е?foo????????????????????δ?testobj---obj2---obj1---Object????????Object????????foo??????????????????????????????????????obj1???????????foo????????????testobj??foo??????????????е???obj1??foo???????obj1дfoo??????????д???????????????????