0

I was trying to make one of my functions dynamic. but I ran into a problem where a method call of my object has to be dynamic via a parameter but when I ty to do this it always gives me an error saying '...' is not a function.

My original call

   datacontext.graph.editUSerSkills(skills).then(function (data) { })

Now I need to get the "editUserSkills" dynamically.

I tried the following two options:

var graphAction = 'editUserSkills';

datacontext.graph.eval(graphAction)(items).then(function (data) {

datacontext.graph[graphAction](items).then(function (data) {

Obviously none of this worked so I really wonder how I should tackle this issue to make it dynamic.

Any help is much appreciated, Cheers.

Rodney Wormsbecher
  • 897
  • 2
  • 17
  • 39
  • 2
    datacontext.graph[graphAction](items).then(function (data) { should have worked. what happened in the second case? – Parijat Purohit Oct 27 '17 at 08:49
  • 1
    `datacontext.graph[graphAction](skills).then(function (data) { })` - see the linked question's answers for details. Your example where you tried to use that syntax used `items` instead of `skills`, perhaps that's the issue? If you still can't work it out from the linked question, please update your question with a **runnable** [mcve] demonstrating the problem, using Stack Snippets (the `[<>]` toolbar button). – T.J. Crowder Oct 27 '17 at 08:49
  • @Philicare those shouldn't make any difference - the OP doesn't need to set an explicit `this` context because it's already the value of `datacontext.graph`. – Alnitak Oct 27 '17 at 08:54
  • my bad, the datacontext.graph[graphAction](skills).then(function (data) { }) it was that I made a mistake in the parameter. thanks for the help – Rodney Wormsbecher Oct 27 '17 at 09:03

0 Answers0