-2

I began using Sublime Text 2 for my Javascript coding and love it. I'm creating a small project that requires input from the user. Normally, or from previous practice, I was able to write:

var x = prompt("What city do you live in?") and have the string assigned to the var x

But, when I run this line of code in ST2 I get:

Exception: ReferenceError: Can't find variable: prompt.

I've installed Package Control but can't find a plug-in to address my need.I installed SublimeREPL and that didn't work for me.

Thanks, this is my first question on Stack. Any comments or assistance is welcomed.

  • 1
    Are you trying to run javascript in sublime text, when the [language for wirting plugins is python (link to documentation)](http://sublimetext.info/docs/en/extensibility/plugins.html) ? – dvhh Aug 28 '15 at 03:09
  • True, ST 2 does not natively run JS. But I followed these directions to create a JS console, and it does work except for a few exceptions i.e I must use debug() in place of console.log() http://www.wikihow.com/Create-a-Javascript-Console-in-Sublime-Text – Mikenuchida Aug 28 '15 at 15:43
  • Even then `prompt` is surely not part of javascriptCore nor node.js API, `window.prompt` is a DOM api, meaning it could be used in a web browser window. Same for `console.log`. – dvhh Aug 29 '15 at 15:42

2 Answers2

1

you cannot run javascript in sublime text, the language to write plugins in python,

the SublimeREPL require extra binary to be installed to run Javascript (probably node.js),

and even then the window.prompt is a browser API, not a javascript function (by default you are running at the window level which provide the default method with the need to prefix by the object name)

In conclusion your Javascript console REPL in most case does not have the prompt function/method/API available

dvhh
  • 4,724
  • 27
  • 33
0

I've never used JS to create sublime plugin, but you could use the function window.show_input_panel. Have a look at the sublime text 2 API.

Matt

math2001
  • 4,167
  • 24
  • 35