Questions tagged [defineproperty]

An ECMAScript 5 method that defines a new property directly on an object, or modifies an existing property on an object, and returns the object.

An ECMAScript 5 method that defines a new property directly on an object, or modifies an existing property on an object, and returns the object.

Object.defineProperty(obj, prop, descriptor)
158 questions
0
votes
0 answers

Read An Object In C# Which Is Created By Object.defineProperty In JavaScript

in my JavaScript code section, an object is created with DefineProperty like this : $("td", tr).each(function (index, td) { var field = $(td).attr("data-field"); var value = $(td).attr("data-value"); if (field…
Farzad Karimi
  • 770
  • 1
  • 12
  • 31
0
votes
1 answer

when a proto obj be defined by defineProperty then it's hasOwnProperty with the same property would be error ,why?

code like below : function def(obj, key) { var val = obj[key]; Object.defineProperty(obj, key, { enumerable: true, configurable: true, get: function reactiveGetter() { return val }, set: function reactiveSetter(newVal)…
cui peng
  • 11
  • 2
0
votes
2 answers

JavaScript: adding method to DOM-Object via prototype - like: Object.defineProperty(Object.prototype, ...)

I want to add some own methods via Object.prototype to work easier with my DOM objects. I found this on SO: How do I write an extension method in JavaScript? (SO link) how to use javascript Object.defineProperty (SO link) : So I tried some code…
Froschkoenig84
  • 566
  • 4
  • 13
0
votes
1 answer

defineproperty on object.prototype does not fire when creating nested objects

I'm just fiddling around trying to understand how his is supposed to work, but this scenario has me confused. Object.defineProperty(Object.prototype, 'a', {set: function() {console.log("Set!");} }); With that method, I assume any time I create an…
user1131308
  • 309
  • 4
  • 12
0
votes
1 answer

Object.definePropery on Array.prototype.push doesnt work

I want to unable the overriding option on Array.prototype.push on my web application. I have tried to do so with Object.defineProperties(Array.prototype, "push", {writable: false}); But got an Uncaught TypeError: Property description must be an…
GMe
  • 1,091
  • 3
  • 13
  • 24
0
votes
0 answers

limitations of Object.defineProperty and whether Object.prototype has to get involved

I want to use the fact the getter of an object property can be overridden. In attempting to find the right syntax, I ran into trouble where using the following syntax works, but the syntax below it and the bit at the bottom, my preferred method, do…
Tim Pozza
  • 498
  • 6
  • 9
0
votes
3 answers

How I can set property of object properties?(js)

I using js and i want set property of object properties var a=42 Object.defineProperty(this,"a",{value:43} )//Error How I can set property of object properties after defining.
Kayrag
  • 19
  • 3
0
votes
1 answer

Performance difference between Object.defineProperty() and Object.defineProperties()

I am looking for a main differences between those two methods. Some sites mentioned readability concerns, but my concern is mainly performance related. Seems like defineProperty() is faster, but i couldn't find out why. var FOR_TIME =…
buriedalive
  • 380
  • 5
  • 12
0
votes
0 answers

Attempting to make Webpack 3 compatible with IE8

Due to some legacy products that require IE8 compatibility mode we must not use Object.defineProperty calls. We are building a single large bundle from TypeScript modules using ES6 syntax. If that matters, we're not utilizing live module loading,…
Zoltán Tamási
  • 12,249
  • 8
  • 65
  • 93
0
votes
0 answers

Watch all properties on objects, including properties created later

Say I have an object, var obj = {}. I want to have a handler invoked when at a later time, any field is retrieved; obj.b. I am aware of proxies, var obj = {}; var proxy = new Proxy(obj, { get(obj, prop) { console.log('get', prop) return…
junvar
  • 11,151
  • 2
  • 30
  • 46
0
votes
4 answers

Assigning object properties (in a loop) and including a setter results in undefined values

This is my first attempt at using Javascript's Object.defineProperty and/or defineProperties and apparently I'm doing it completely incorrectly. I am passing a cfg object into a Javascript function constructor, then inside that constructor am…
Dexygen
  • 12,287
  • 13
  • 80
  • 147
0
votes
2 answers

Vue/Vuex > Cannot track state changed when I use Object.defineProperty() method

I use Vue.js and Vuex. I make a simple todolist app. I make a done toggle button with Vuex using Object.defineProperty() method. When I click done toggle button, Vue and Vuex cannot trace change immediately. It only trace change when I just reassign…
KunhoLee
  • 25
  • 4
0
votes
1 answer

How to allow to add property on object but stop Modifying set of properties on object

I have some global object CD and it has set of properties as follows: window.cd = { config:{ title:"..." } a:func..., b:56, c:.. } I want user to allow add properties to cd and cd.config but properties cd.a, cd.b, cd.config.title to…
Akhilesh Kumar
  • 9,085
  • 13
  • 57
  • 95
0
votes
2 answers

How to prevent object properties to not be extended in javascript

Im trying to seal an object property . My question is ,here i have given Object.seal(personObject),this particular object is sealed and does not allow to configure or make any extensions in this object,but as i did not mention on personObject_2 it…
Srisa
  • 269
  • 1
  • 3
  • 9
0
votes
1 answer

Update JS define property from outside

I use the following code and I want from other module to update some property,how should I do that? This is the module code(In real there is more properties...) "use strict" function define(name, value) { Object.defineProperty(exports, name, { …
user6124024