JavaScript set() method

The Javascript handler set() method creates a collection of unique items.

Syntax:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
set: function(target, property, value, receiver)
set: function(target, property, value, receiver)
set: function(target, property, value, receiver)

Parameters:
target: It represents the target object.
property: It represents the name or value of the property.
value: It represents the new of the property.
receiver: It represents the proxy itself.

Return:
Boolean.

Example:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<body>
<script>
var handler = { foo: 1 };
var d = new Proxy(handler, {
set: function(a,b,c,d) {
document.writeln ('Hello World!');
a[b] = c.toUpperCase();
}});
d.foo = 'Howz U?';
document.writeln(handler.foo);
</script>
</body>
</html>
<!DOCTYPE html> <html> <body> <script> var handler = { foo: 1 }; var d = new Proxy(handler, { set: function(a,b,c,d) { document.writeln ('Hello World!'); a[b] = c.toUpperCase(); }}); d.foo = 'Howz U?'; document.writeln(handler.foo); </script> </body> </html>
<!DOCTYPE html>
<html>
<body>
<script>
var handler = { foo: 1 };
var d = new Proxy(handler, {
set: function(a,b,c,d) {
document.writeln ('Hello World!');
a[b] = c.toUpperCase();
}});
d.foo = 'Howz U?';
document.writeln(handler.foo);
</script>
</body>
</html>