object-properties

Why is this object property undefined?

喜你入骨 提交于 2019-12-04 02:53:22
Consider the code below. The first console.log correctly logs the image, and you can see its properties in the image below. However, when I try logging one if its properties to the console, I get undefined ! console.log(that.data[0].cards); //works -- see image below console.log(that.data[0].cards.E); //undefined console.log(that.data[0].cards['E']); //undefined console.log(that.data[0].cards.hasOwnProperty('E')); //false var test = JSON.stringify(that.data[0]); console.log(test); // {} for( var key in that.data[0].cards ) { console.log('hello????') //doesn't appear in the console } console

Access static object property through variable name

╄→гoц情女王★ 提交于 2019-12-01 20:11:49
I know its possible to access an object property/method using a variable as its name ex.: $propName = 'something'; $something = $object->$propName; Is it possible to do the same w/ constants or static properties? I've tried: $constName = 'MY_CONST'; MyCLass::{$constName}; and $obj::{$constName}; But nothing seems to work and I couldn't find it anywhere. Use: Class::$$constName , this is similar to normal variable variables . Demo: <?php class MyClass { public static $var = 'A'; } $name = 'var'; echo MyClass::$$name; // echoes 'A' Constants can be access with the constant function: constant(

Variable Variables Pointing to Arrays or Nested Objects

时光总嘲笑我的痴心妄想 提交于 2019-11-27 16:16:31
Is it possible to create a variable variable pointing to an array or to nested objects? The php docs specifically say you cannot point to SuperGlobals but its unclear (to me at least) if this applies to arrays in general. Here is my try at the array var var. // Array Example $arrayTest = array('value0', 'value1'); ${arrayVarTest} = 'arrayTest[1]'; // This returns the correct 'value1' echo $arrayTest[1]; // This returns null echo ${$arrayVarTest}; Here is some simple code to show what I mean by object var var. ${OBJVarVar} = 'classObj->obj'; // This should return the values of $classObj->obj

Variable Variables Pointing to Arrays or Nested Objects

无人久伴 提交于 2019-11-26 22:26:35
问题 Is it possible to create a variable variable pointing to an array or to nested objects? The php docs specifically say you cannot point to SuperGlobals but its unclear (to me at least) if this applies to arrays in general. Here is my try at the array var var. // Array Example $arrayTest = array('value0', 'value1'); ${arrayVarTest} = 'arrayTest[1]'; // This returns the correct 'value1' echo $arrayTest[1]; // This returns null echo ${$arrayVarTest}; Here is some simple code to show what I mean

Javascript - catch access to property of object

£可爱£侵袭症+ 提交于 2019-11-26 22:14:48
Is it possible to capture when a (any) property of an object is accessed, or attempting to be accessed? Example: I have created custom object Foo var Foo = (function(){ var self = {}; //... set a few properties return self; })(); Then there is some action against Foo - someone tries to access property bar Foo.bar Is there way (prototype, perhaps) to capture this? bar may be undefined on Foo . I could suffice with capturing any attempted access to undefined properties. For instance, if bar is undefined on Foo , and Foo.bar is attempted, something like: Foo.prototype.undefined = function(){ var

Javascript - catch access to property of object [duplicate]

佐手、 提交于 2019-11-26 08:16:11
问题 This question already has an answer here: Is it possible to implement dynamic getters/setters in JavaScript? 3 answers Is it possible to capture when a (any) property of an object is accessed, or attempting to be accessed? Example: I have created custom object Foo var Foo = (function(){ var self = {}; //... set a few properties return self; })(); Then there is some action against Foo - someone tries to access property bar Foo.bar Is there way (prototype, perhaps) to capture this? bar may be

How do I remove a property from a JavaScript object?

痴心易碎 提交于 2019-11-25 22:53:21
问题 Say I create an object as follows: var myObject = { \"ircEvent\": \"PRIVMSG\", \"method\": \"newURI\", \"regex\": \"^http://.*\" }; What is the best way to remove the property regex to end up with new myObject as follows? var myObject = { \"ircEvent\": \"PRIVMSG\", \"method\": \"newURI\" }; 回答1: Like this: delete myObject.regex; // or, delete myObject['regex']; // or, var prop = "regex"; delete myObject[prop]; Demo var myObject = { "ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://