【发布时间】:2015-10-27 01:30:48
【问题描述】:
我需要在 Something 类上发现函数 'foo',但它不起作用。这是因为我错过了使用类语法的微妙之处,还是因为 babel 或其他什么?我更愿意尽可能使用“类”,但发现对我来说更重要。
我们那里的天才知道这个吗?
class Something {
constructor() {
}
foo() {
console.log("foo");
}
}
var something = {
foo : function() {
console.log("foo");
}
}
var result = Object.getOwnPropertyNames(new Something()).join(", ");
console.log("new Something() = %s", result);
result = Object.getOwnPropertyNames(Something.__proto__).join(", ");
console.log("Something.__proto__ = %s", result);
result = Object.getOwnPropertyNames(something).join(", ");
console.log("var something = %s", result);
产生:
new Something() =
Something.__proto__ = length, name, arguments, caller, constructor, bind, call, apply, toString
var something = foo
【问题讨论】:
标签: javascript ecmascript-6 babeljs