| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Functions/set | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.
set .
const language = {
set current(name) {
this.log.push(name);
},
log: [],
};
language.current = "EN";
language.current = "FA";
console.log(language.log);
// Expected output: Array ["EN", "FA"]
{set prop(val) { . . . }}
{set [expression](val) { . . . }}
prop.
valprop .
expressionECMAScript 2015 , .
JavaScript (setter) . (getter) ' ' . , .
set .
.
.
, .
{
set x() { }, set x() { }
}
, .
{
x: ..., set x() { }
}
language current . current , log .
const language = {
set current(name) {
this.log.push(name);
},
log: [],
};
language.current = "EN";
console.log(language.log); // ['EN']
language.current = "FA";
console.log(language.log); // ['EN', 'FA']
current , undefined .
delete delete .
delete language.current;
defineProperty const o = { a: 0 };
Object.defineProperty(o, "b", {
set: function (x) {
this.a = x / 2;
},
});
o.b = 10;
// , a 10 / 2 = 5
console.log(o.a);
// 5
const expr = "foo";
const obj = {
baz: "bar",
set [expr](v) {
this.baz = v;
},
};
console.log(obj.baz);
// "bar"
obj.foo = "baz";
// run the setter
console.log(obj.baz);
// "baz"
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-method-definitions |
deleteObject.defineProperty()Object.prototype.__defineGetter__()Object.prototype.__defineSetter__()This page was last modified on 2026 7 15 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |