Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Basic Javascript Function

Tags:

javascript

I am trying to learn more about Javascript, I have been coding with PHP and making web application for years, I have basic knowledge of JS, most of the JS I have used has been already coded and me just plugging it in until recently, in the past years I have been able to do a lot with jQuery.

I have noticed that Stack Overflow uses jQuery more then most sites I have seen, it is beautiful all the JS functionality they have here.

So a basic question, Stack Overflow uses StackExchange in front of most of the JS code that I have seen on here. What exactly is that doing? To me I would want to say it is like a Class name but I read JS does not have classes.

Here is an example code

StackExchange.debug.log("no cache breaker for " + q);

Can you break this down for me to explain what the StackExchange, debug, log are? I mean I can tell that log must be a function call but the others?


PS) Please don't move this to META as it is a JS question and not specific to StackOverflow Also feel free to edit the question title and delete this line if you can think of a better title, thanks

like image 861
JasonDavis Avatar asked Jan 28 '26 06:01

JasonDavis


1 Answers

Think of StackExchange as something much like the global jQuery function, "$" (or "jQuery"). It's just a global reference to an object that has functions and other properties.

Thus, "debug" is a property of the global "StackExchange" object, and in turn "log" is a property of the "debug" object. In this case, the "log" property references a function, which clearly is a debugging tool.

It's a debatable point whether JavaScript has "classes" or not, but it definitely has objects. (By "debatable" I mean it's a subject that fills an endless stream of blog posts and Stackoverflow questions :-)

That is, in fact, basic JavaScript. There's nothing super fancy or tricky about it.

like image 95
Pointy Avatar answered Jan 30 '26 19:01

Pointy