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
1 answer

Set property within object initialisation before Object.defineProperty

I would like to set the property x when I first initialise my object, and then call Object.defineProperty. If I try to first access foo.x the console tells me that "value is not defined". var foo = {x:20}; Object.defineProperty(foo, "x", { …
yvesb
  • 95
  • 9
0
votes
1 answer

Is defineProperty method inherited from Object?

If all objects inherit from Object then why can't i use the defineProperty method of Object in this way? var car = {name:"honda"} car.defineProperty(car, "jow", {value:"jow"}) alert(car.jow) Thx for your insight,
kevinius
  • 4,232
  • 7
  • 48
  • 79
0
votes
2 answers

use defineProperty get and value together

If I use get with defineProperty Object.defineProperty(Object.prototype,'parent',{ get:function(){return this.parentNode} }); and I can call it like: document.body.parent, then it works. When I use value with…
Naz
  • 2,520
  • 2
  • 16
  • 23
0
votes
0 answers

Using Object.defineProperty to create instance-specific properties within a prototype?

I'm trying to create a property within a prototype so it will be available in all instances (can't put it in the constructor and would prefer to not create it via instance.propertyname = *; if at all possible. As an example the code below: function…
CoryG
  • 2,429
  • 3
  • 25
  • 60
0
votes
1 answer

Is defineProperty for elements broken in iOS6?

JavaScript's defineProperty and __defineSetter do not work on elements in iOS6. It works properly on all other browsers and on previous versions of iOS. Anybody know more about this?
ghenne
  • 1,903
  • 2
  • 19
  • 29
-1
votes
1 answer

Using toString when setting object prototype to null

If I set the prototype to null, then how come I can still use toString on the object? var nakedObject=Object.create(null,{ name:{ configurable:true, enumerable:true, value:"Hello", writable:true } }); …
akotch
  • 215
  • 5
  • 11
-1
votes
2 answers

How can I add a property to Object.prototype without it being applied to Number.prototype?

My goal is to create a master_script.js. A handler file mainly used in development. A subsection of this file is dedicated to customizing the prototypes of the foundation objects: String Number Array Object Date Function Boolean So as I'm…
LostInCyberSpace
  • 413
  • 4
  • 19
-3
votes
1 answer

Where does a local variable get stored, and how can I define a getter/setter for one?

So in JavaScript, I know that when you define a variable in the global scope, like this, let a = 0; console.log(a); // > 0 it's (more or less) the same as defining a property on the window object: window.a = 0; console.log(a); // > 0, exactly the…
1 2 3
10
11