小编MOH*_*L M的帖子

javascript 类中相同的方法或变量名称的行为不同

class Parent{
    method(){
        console.log("Parent");
    }
}
class Child extends Parent{
    method(){
        console.log("Parent");
    }
}
var child = new Child();
console.log(child.method);
Run Code Online (Sandbox Code Playgroud)

子类中的控制台返回方法是预期的行为。

class Parent{
    method = "sss"
}
class Child extends Parent{
    method(){
        console.log("Child")
    }
}
var child = new Child();
console.log(child.method)
Run Code Online (Sandbox Code Playgroud)

为什么控制台在父类中返回方法变量 - “sss”?

javascript class es6-class

5
推荐指数
1
解决办法
131
查看次数

标签 统计

class ×1

es6-class ×1

javascript ×1