tags:

views:

56

answers:

3

I recently installed v8 in my system and was trying few javascript programs, but some of the output functions like alert, prompt etc. is not being recognised by it. The same program if i run it in browser is working fine. Am I missing something?

+1  A: 

alert() and prompt() are methods of the DOM, so you only have them in a browser environment.

For more information see The DOM and JavaScript on MDC.

Skilldrick
so using javascript we r accessing DOM methods ur saying ? if its true then is there any other language from which we can access these DOM methods ?
Rahul
Yep. The default namespace for browser-based JS is `window`. These functions are actually `window.alert()` and `window.prompt()`.
Ryan Kinal
Yes, @Rahul, the `alert()` function is `window.alert()`, and there's no `window` in a V8 program. (There's a global context, but it's not `window`, which is part of the **browser** not Javascript.)
Pointy
so basically javascript is one of the ways to use DOM methods which are embedded in browser , so if a browser is built in which interfaces are provided by a different language , lets say python then in that case can python be used as client side scripting ?Ps: sorry if i sound ridiculous , i am pretty new to these stuff
Rahul
-1 they are not methods of the DOM
Šime Vidas
@Šime Vidas Yes they are: https://developer.mozilla.org/en/The_DOM_and_JavaScript "You would then use the DOM "alert()" method to display the string in a dialog to the user."
Skilldrick
@Rahul - see my link: "Other known implementations of the DOM include Perl, Java, ActiveX, Python, and probably others. This is of course only possible thanks to the language-neutrality of the DOM."
Skilldrick
@Rahul - you won't be able to safely use Python as a browser scripting language unless all the browsers you're supporting allow Python as a scripting language (which is basically none).
Skilldrick
The DOM is defined by W3C. There are 11 DOM standards. You can use my w3viewer.com to browse them. The alert method is not defined in any of them, so it is not a DOM method. There are literally hundreds of browser objects that are not defined by DOM standards and those objects are not considered part of the DOM. Some people don't understand this distinction, so they think that all browser objects are DOM objects. I assume that this mozilla article is somewhat old.
Šime Vidas
@Šime I think this depends on how strict your definition of the DOM is. If you're going to go by the standards then fine. But if you think of the DOM as the API by which JavaScript communicates with the browser, then my definition is valid. I agree that this definition is much looser and non-standard, but I've found it to be the most widely accepted definition.
Skilldrick
so can i manually integrate the DOM API and javascript ? well i know sounds ridiculous cuz thats wat a browser does , but i intend to understand browser more profoundly .
Rahul
@Skilldrick So do you consider all browser objects to be part of the DOM? What about Web Workers, Web storage, the File object, the XMLHttpRequest object, Indexed database? There are lots of APIs that are implemented in the browsers. It would be wrong to refer to them as part of the DOM. So, the line has to be drawn somewhere, and I believe that the best place to draw the line is: If the object/interface is defined by a DOM standard, then it is considered part of the DOM.
Šime Vidas
@Šime - OK, fair enough, that makes sense.
Skilldrick
+3  A: 

Yes: the functions you mention aren't actually part of the JS language specification, but a web-browser specific extension of it.

Piskvor
-1 they are not part of the DOM
Šime Vidas
@Šime Vidas: You are correct and I was wrong; edited.
Piskvor
+3  A: 
Šime Vidas
https://developer.mozilla.org/en/The_DOM_and_JavaScript
Skilldrick
so basically javascript is used to handle these things . so is there a way that i can use these host objects or even DOM objects using standalone javascript interpreter ?
Rahul
Host objects are defined by the environment in which the JavaScript code runs. In the browser, the browser is the environment. I am not sure in what environment your code runs. How did you install v8? How do you run it?
Šime Vidas
i followed this thread http://stackoverflow.com/questions/1802478/running-v8-javascript-engine-standalone
Rahul
So you are running JavaScript from the console. Then I assume there could be some custom functions defined which are used to print to the console (instead of alert)... Try to find the documentation of V8
Šime Vidas
I intend to understand web browsers more profoundly , thus decided to coalsce these indivual units .Is there any way i can integrate this DOM API
Rahul
The DOM is a set of open standards. Each browser implements these standards to certain extends. You can how well the browsers confer to the standard here: http://en.wikipedia.org/wiki/Comparison_of_layout_engines_(Document_Object_Model) There might be a JavaScript library that simulates the DOM API, however, since the browsers don't implement the standard fully, it is not enough to know the standard, but you need also earn experience of how each browser implements the standard
Šime Vidas