0

Douglas Crokford のビデオからこの例を試していますが、私の知る限り、新しいオブジェクトを変更しても古いオブジェクトは変更されません。

   var oldObject = {
        firstMethod:function(){
            console.log("This is first method");
        },
        secondMethod:function(){
            console.log("This is second method");
        }
    }

    var newObject = Object(oldObject);

    newObject.thirdMethod=function(){
        console.log("thirdMethod");
    }

    newObject.firstMethod=function(){
        console.log("I am not first method");
    }

    newObject.firstMethod();
    oldObject.firstMethod();

出力:

I am not first method
I am not first method

でも予想していたのですが、

I am not first method
This is first method

どこが間違っているか教えてください。

4

4 に答える 4