Object.prototype.__defineSetter__() - JavaScript | MDN Skip to main content Skip to search MDN HTML HTML: Markup language HTML reference Elements Global attributes Attributes See all… HTML guides Responsive images HTML cheatsheet Date & time formats See all… Markup languages SVG MathML XML CSS CSS: Styling language CSS reference Properties Selectors At-rules Values See all… CSS guides Box model Animations Flexbox Colors See all… Layout cookbook Column layouts Centering an element Card component See all… JavaScriptJS JavaScript: Scripting language JS reference Standard built-in objects Expressions & operators Statements & declarations Functions See all… JS guides Control flow & error handing Loops and iteration Working with objects Using classes See all… Web APIs Web APIs: Programming interfaces Web API reference File system API Fetch API Geolocation API HTML DOM API Push API Service worker API See all… Web API guides Using the Web animation API Using the Fetch API Working with the History API Using the Web speech API Using web workers All All web technology Technologies Accessibility HTTP URI Web extensions WebAssembly WebDriver See all… Topics Media Performance Privacy Security Progressive web apps Learn Learn web development Frontend developer course Getting started modules Core modules MDN Curriculum Check out the video course from Scrimba, our partner Learn HTML Structuring content with HTML module Learn CSS CSS styling basics module CSS layout module Learn JavaScript Dynamic scripting with JavaScript module Tools Discover our tools Playground HTTP Observatory Border-image generator Border-radius generator Box-shadow generator Color format converter Color mixer Shape generator About Get to know MDN better About MDN Advertise with us Community MDN on GitHub Blog Toggle sidebar Tecnologia Web para desenvolvedores JavaScript Referência JavaScript Objetos Globais Object Object.prototype.__defineSetter__() Theme OS default Light Dark Português (do Brasil) Remember language Learn more Deutsch English (US) Français 日本語 한국어 Português (do Brasil) Русский 中文 (简体) Esta página foi traduzida do inglês pela comunidade. Saiba mais e junte-se à comunidade MDN Web Docs. View in English Always switch to English Object.prototype.__defineSetter__() Aviso: Esta funcionalidade está depreciada em favor da definição de setters usando a sintaxe de inicialização de objeto ou a API Object.defineProperty(). Entretando, como ele é largamente implementado e usado na Web, é bem improvável que os navegadores vão parar de implementá-lo. O método __defineSetter__ vincula uma propriedade de um objeto a uma função a ser chamada quando é feita uma tentativa de atribuir algo a aquela propriedade. In this article Sintaxe Descrição Exemplos Especificações Compatibilidade com navegadores Veja também Sintaxe obj.__defineSetter__(prop, fun) Parâmetros prop Uma cadeia de caracteres (string) contendo o nome da propriedade que vai ser vinculada a função dada. fun A função a ser chamada quando houver uma tentativa de atribuir na propriedade especificada. Esta função toma a forma js function(val) { . . . } val Um apelido para a variável que contém o valor que se tentou atribuir a prop. Valor de retorno undefined. Descrição O método __defineSetter__ permite um setter ser definido a um objeto pré-existente. Exemplos Não padronizados e forma depreciada js var o = {}; o.__defineSetter__("value", function (val) { this.anotherValue = val; }); o.value = 5; console.log(o.value); // undefined console.log(o.anotherValue); // 5 Formas compatíveis padronizadas js // Usando o operador set var o = { set value(val) { this.anotherValue = val; }, }; o.value = 5; console.log(o.value); // undefined console.log(o.anotherValue); // 5 // Usando Object.defineProperty var o = {}; Object.defineProperty(o, "value", { set: function (val) { this.anotherValue = val; }, }); o.value = 5; console.log(o.value); // undefined console.log(o.anotherValue); // 5 Especificações Specification ECMAScript® 2027 Language Specification # sec-object.prototype.__defineSetter__ Compatibilidade com navegadores Enable JavaScript to view this browser compatibility table. Veja também Object.prototype.__defineGetter__() Operador set Object.defineProperty() Object.prototype.__lookupGetter__() Object.prototype.__lookupSetter__() JS Guide: Defining Getters and Setters [Blog Post] Deprecation of __defineGetter__ and __defineSetter__ bug 647423 Help improve MDN Was this page helpful to you? Yes No Learn how to contribute This page was last modified on 22 de mai. de 2026 by MDN contributors. View this page on GitHub • Report a problem with this content Filter sidebar Clear filter input Objetos Globais Object Construtor Object() Métodos estáticos Object.assign() Object.create() Object.defineProperties() Object.defineProperty() Object.entries() Object.freeze() Object.fromEntries() Object.getOwnPropertyDescriptor() Object.getOwnPropertyDescriptors() Object.getOwnPropertyNames() Object.getOwnPropertySymbols() Object.getPrototypeOf() groupBy() Object.hasOwn() Object.is() Object.isExtensible() Object.isFrozen() Object.isSealed() Object.keys() Object.preventExtensions() Object.seal() Object.setPrototypeOf() Object.values() Métodos de instância Object.prototype.__defineGetter__() Object.prototype.__defineSetter__() Object.prototype.__lookupGetter__() Object.prototype.__lookupSetter__() Object.prototype.hasOwnProperty() Object.prototype.isPrototypeOf() Object.prototype.propertyIsEnumerable() Object.prototype.toLocaleString() Object.prototype.toString() Object.prototype.valueOf() Propriedades de instância Object.prototype.__proto__ Object.prototype.constructor Herança Object/Function Métodos estáticos Function.prototype.apply() Function.prototype.bind() Function.prototype.call() Function.prototype.toString() [Symbol.hasInstance]() Propriedades estáticas Function.displayName Function.length Function.name prototype Function.arguments Function.caller Métodos de instância Object.prototype.__defineGetter__() Object.prototype.__defineSetter__() Object.prototype.__lookupGetter__() Object.prototype.__lookupSetter__() Object.prototype.hasOwnProperty() Object.prototype.isPrototypeOf() Object.prototype.propertyIsEnumerable() Object.prototype.toLocaleString() Object.prototype.toString() Object.prototype.valueOf() Propriedades de instância Object.prototype.__proto__ Object.prototype.constructor MDN Your blueprint for a better internet. MDN About Blog Mozilla careers Advertise with us MDN Plus Product help Contribute MDN Community Community resources Writing guidelines MDN Discord MDN on GitHub Developers Web technologies Learn web development Guides Tutorials Glossary Hacks blog Mozilla Website Privacy Notice Telemetry Settings Legal Community Participation Guidelines Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.