2
var config = {
  paths: {
    myFiles: 'folder/files'
  },

  task: {
    sync: {
      files: [
        config.paths.myFiles + '/*.jade'
      ]
    },
   [...]
};

How can i access paths if i am inside task?

I tried using

config.paths.myFiles + '/*.jade'

and also just

paths.myFiles + '/*.jade'

(cause "task" is also inside the "config" variable)

But im getting 'unexpected identifier' idk why.

Melo
  • 71
  • 1
  • 8
  • I know this is a very basic javascript question. What should i be studying in order to learn these things? Javascript Objects? – Melo May 27 '15 at 13:17
  • Could you try `self`? I'd assume self would give you `config`. – evolutionxbox May 27 '15 at 13:17
  • Im trying to get a directory. folder/files/*jade. Im using "folder/files" everywhere, so im creating a variable for this, but idk how can i get this variable when im inside task.. – Melo May 27 '15 at 13:20
  • in your case - you can't :-) but you can use function that return object instaed object literal – Grundy May 27 '15 at 13:20
  • 2
    Try google `Self-references in object literal ` . – xdazz May 27 '15 at 13:21
  • I think you may have to initialise that folder after `config` has been created. Or use a function to return the value you want. – evolutionxbox May 27 '15 at 13:21
  • @Grundy I have also flagged it too. It makes sense to direct people toward an already complete answer. – evolutionxbox May 27 '15 at 13:23
  • @adeneo Referencing the property like OP has done already, gives the following error: `Uncaught TypeError: Cannot read property 'myFiles' of undefined` – evolutionxbox May 27 '15 at 13:26
  • @evolutionxbox - Yeah, I deleted my comment, you can't reference a variable inside the variable that way. Still, the error the OP is getting suggest a syntax error. – adeneo May 27 '15 at 13:27
  • @evolutionxbox, but in title question - _unexpected identifier_, so possibly adeneo right and in code also syntax error – Grundy May 27 '15 at 13:28
  • 2
    Anyway, here's how to solve it -> http://jsfiddle.net/adeneo/ww1r3vhd/ – adeneo May 27 '15 at 13:29
  • You are missing a closing bracket in your code sample. Which would give you this error `unexpected identifier` – khollenbeck May 27 '15 at 13:30
  • @adeneo That makes sense. – evolutionxbox May 27 '15 at 13:30
  • @adeneo Why dont you post it as an answer? – Melo May 27 '15 at 13:31
  • @PedroMelo because this question already answered :-) – Grundy May 27 '15 at 13:33
  • of course :) Thank you very much guys. Helped me a lot. sorry, i didnt know it was duplicated, because i didnt know how to search it properly. Have a nice day! – Melo May 27 '15 at 13:36
  • Just a little question: if i keep studying JavaScript Object, it will be enough for me to know things like that and learn the 'Vocabulary', properties, object literal etc? – Melo May 27 '15 at 13:38

0 Answers0