C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript handler.defineProperty() MethodThe handler.defineProperty() method can define the new properties. It can also modify the existing properties directly on an object. It is trap for Object.defineProper(). This method can be used in two situations.
SyntaxdefineProperty: function(target, property, descriptor) ParametersTarget: The target object. Property: Retrieved property description. Descriptor: The property being defined or modified. Return valueThis method returns a Boolean Browser Support
Example 1var target = {} target.foo = 'bar' document.writeln(Object.getOwnPropertyDescriptor(target, 'foo')) Output: [object Object] Example 2var xyz = {}; var proxy = new Proxy(xyz, { defineProperty: function(target, name, propertyDescriptor) { document.writeln('in defineProperty'); return Object.defineProperty(target, name, propertyDescriptor); } }); Object.defineProperty(proxy, 'bar', {} ); Output: in defineProperty Example 3var xyz ={}; var hu = {}; var proxy = new Proxy(xyz, { defineProperty: function(target, name, propertyDescriptor) { document.writeln('Learn Java Script'); return Object.defineProperty(target, name, propertyDescriptor); } }); var pro= new Proxy(hu, { defineProperty: function(target, name, propertyDescriptor) { document.writeln('Proxt Method '); return Object.defineProperty(target, name, propertyDescriptor); } }); Object.defineProperty(proxy, 'bar', {} ); Object.defineProperty(pro, 'hug', {} ); Output: Learn Java Script Proxt Method
Next TopicJavaScript handler
|