Df.717 2024-02-23 08:43 采纳率: 28.6%
浏览 10

if三目简写 左边无效


<script>
    function Clone(obj){
        for (var key in obj )
        {
            this[key]=(typeof obj[key]="object")?new Clone(obj[key]):obj[key];
        };

    };
    function Person(name,age,marry,sex){
        this.name=name;
        this.age=age;
        this.marry=marry;
        this.sex=sex;
    };
    Person.prototype.showName=function(){
        alert(this.name);
    };

    function PersonChild(pArr,weight){
        Person.apply(pArr,this);
        this weight=weight;
    };
    
    PersonChild.prototype=new Clone(Person.prototype);
    PersonChild.prototype.showAge=function(){
        alert (this.age);
    };

    alert(Person.prototype.showAge);
  </script>

this[key]=(typeof obj[key]="object")?new Clone(obj[key]):obj[key];
这串代码,左边无效是为什么

img

  • 写回答

2条回答 默认 最新

  • sy-sy- 2024-02-23 09:04
    关注

    typeof obj[key]="object"
    少了等于号
    === 严格相等
    == 宽松相等
    = 赋值

    评论

报告相同问题?

问题事件

  • 创建了问题 2月23日