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

Date as a constructor and as a function

var a = Date; Object.defineProperty(window, "Date", { get: function() { console.log(this); return a; } }); (new Date); Date(); How can I know, when Date is being called as a constructor(with "new"), and when it's being called as a…
0
votes
1 answer

How can I use an image instead of a shape for a node in graph view in Soley Studio?

I am setting up my graph view template in Soley Studio. In some pre-installed solutions I saw that nodes in graph view have been visualized with an icon or graphic instead of a circle, rectangle, etc. I want to define my properties for a node class…
hnnes
  • 17
  • 6
0
votes
0 answers

Override "scrollTop" property and reach value in getter

for a custom scrollbar script I want to override the default scrolltop property. Now I have the problem, that I need to reach the value first to modify it. I use Object.defineProperty( document.documentElement, "scrollTop", { …
Simon
  • 26
  • 4
0
votes
2 answers

how to use 'set' on object properties when the property type has a 'set' of it's own?

If '_position' is a Point object member of Sprite, with Number members x and y, and its own get/set definitions, how can I apply a higher level 'set' so this will work (EDIT: I would like to reach the 'set' function in Sprite, rather than the 'set'…
PeteB
  • 372
  • 1
  • 10
0
votes
1 answer

Using Object.defineProperty on elem.dataset, but property is still changable

I am trying to set an unchangeable property on the dataset of a canvas element using Object.defineProperty. On a normal object this works fine. But when I try to do it on a dataset object, the property is still changeable.
Greg Hornby
  • 7,443
  • 1
  • 18
  • 17
0
votes
2 answers

how to overload = operator with js es5 Object.defineProperty

I what to overload the = operator for JS objects using Object.defineProperty. var log = console.log.bind(console); var obj = { }; Object.defineProperty(obj,'var', { get: function() { log('get'); return obj._var; }, set: function(v) { log('set');…
amin
  • 3,672
  • 5
  • 33
  • 61
0
votes
1 answer

Object.defineProperty data binding scope

I have been playing with the javascript Object.defineProperty to create data binding. I did get it to work. My question is has to do with something else. I have a for html query to look for elements with the attribute 'data-bind' and loop through…
Daniel
  • 4,816
  • 3
  • 27
  • 31
0
votes
1 answer

Call parents implementation in Object.defineProperty

I use javascript prototypal inheritance where A "inherits" B. B uses defineProperty to define a setter for property prop. In A I want to override this behaviour: Function.prototype.inherits = function (parent) { this.prototype =…
0
votes
1 answer

how to define attributes for all properties of an object simultaneously (or set default)

I'm writing an AngularJS service provider (function) that: takes results from a number of different tables of an SQLite database returns the object to various controller functions The service queries different tables (which have different…
goredwards
  • 2,486
  • 2
  • 30
  • 40
0
votes
1 answer

Safari javascript error trying to define "remove" Element method

I have several definitions in my personal library, this one is generating error in Safari: Object.defineProperty(Element.prototype, "remove", { enumerable: false, configurable: false, writable: false, value: function(){ …
Gustavo
  • 1,673
  • 4
  • 24
  • 39
0
votes
1 answer

Conditionally invoke/prevent invocation of setter in Javascript's defineProperty object

Is there a way to catch a Javascript set function in defineProperty, perform some logic and then decide whether to actually allow the original set function to be invoked? Example var scope = {}; scope.myVar = 1; scope._myVar = scope.myVar;…
Jeremy Friesen
  • 383
  • 1
  • 3
  • 13
0
votes
1 answer

Use defineProperty with objects as values

short question: Can i use objects as value inside of a defineProperty call? Currently i have the problem that all instances of a class share the same object. Little example: var Test = function () { }; var p = Test.prototype; …
Shutterfly
  • 199
  • 12
0
votes
0 answers

IE9 JavaScript - using Object.defineProperty on window.location

Object.defineProperty(window.location, "x", function(){}); I use Object.defineProperty to add properties to objects. In Firefox and Chrome adding properties and methods to window.location works fine in this way, however in IE9 I receive an "Object…
0
votes
1 answer

issue in accessing object javascript getter

I am writing getter and setters dynamically. my code is buggy. I need help in correcting it. Portion of my code looks like following: var a = {}; var myArray = ["abc", "xyz", "bbb"]; for (var i = 0; i < myArray.length: i++) { var tempVar =…
Denzz
  • 1,025
  • 2
  • 11
  • 18
0
votes
2 answers

Javascript defineProperty and Object.keys return dilemma

/** * @author paula */ var myObj = {}; Object.defineProperty(myObj, "prop1", { get: function(){return this._prop1;}, set:function(value){this._prop1 = value;}, enumerable:true}); Object.keys(myObj) // Note…
Paula Cogeanu
  • 231
  • 1
  • 10
1 2 3
10
11