一部のプロジェクトは使用Object.create()
またはObject.defineProperties()
機能します。お勧めですか?の違いは何ですか
x = Object.create(null);
vs
x = {}
と
x = {}
x.__proto__.hello = function() {
console.log("hello");
}
vs
x = Object.create(null);
Object.defineProperty(x, "hello", {
value: function() {
console.log("hello");
}
});
defineProperty/create
私には非常に冗長で長いようです。いつ/なぜそれらを使用するのですか?おそらく、ゲッター/セッター/オーバーライドプロパティを強制するのが良いかもしれませんか?