什么是__defineGetter __()和__defineSetter __()函数? [英] What are __defineGetter__() and __defineSetter__() functions?
问题描述
什么是 __ defineGetter __()
和 __ defineSetter __()
每个对象的原型中的函数
?
推荐答案
请参阅 MDN docs 这里有一个描述和示例代码:
See the MDN docs here for a description and example code:
getter是一种获取特定属性值的方法。 setter是一种设置特定属性值的方法。您可以在任何预定义的核心对象或支持添加新属性的用户定义对象上定义getter和setter。
A getter is a method that gets the value of a specific property. A setter is a method that sets the value of a specific property. You can define getters and setters on any predefined core object or user-defined object that supports the addition of new properties.
如上所述文档(和@ cwallenpoole), __ define [GS] etter __()
函数现已弃用。 这篇文章。我相信 defineProperty()函数现在是首选语法。
As noted in the docs (and by @ cwallenpoole), __define[GS]etter__()
functions are now deprecated. There's a lot more detail in this article. I believe the defineProperty() function is now the preferred syntax.
这篇关于什么是__defineGetter __()和__defineSetter __()函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!