javascript - How can I use defined key in another key/value pair -


i have javascript object:

return {    accdocs: {       query: function() {          ...       },       deleteandquery: function() {          ...          accdocs.query(); //error: accdocs not defined       }    } } 

but, returns error says accdocs not defined.
how can achieve this?

variables , properties on objects different things. cannot access property of object without specifying object mean.

you can probably access using this keyword:

this.query(); 

keeping in mind value of this vary depending on how function called (when a.b.c.d.accdocs.deleteandquery() called, this inside deleteandquery accdocs first object left of last ., if first copy query variable , call query(), pass settimeout, or if use call or apply value of this change).

for more robustness (but less flexibility, since being able change context can useful) can store object in variable can access name.

var accdocs = {     query: function() {             ...     },     deleteandquery: function() {             ...         accdocs.query();     } };  return { accdocs: accdocs }; 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -