0

Looking at some sample javascript code at http://alexgorbatchev.com/SyntaxHighlighter/manual/api/autoloader.html I see:

<script src="shCore.js" type="text/javascript"></script>
<script src="shAutoloader.js" type="text/javascript"></script>
<script type="text/javascript">
SyntaxHighlighter.autoloader(
  'js jscript javascript  /js/shBrushJScript.js',
  'applescript            /js/shBrushAppleScript.js'
);

SyntaxHighlighter.all();
</script>

In this example, what is a SyntaxHighlighter? a global variable? a singleton? a what?

dublintech
  • 16,815
  • 29
  • 84
  • 115

2 Answers2

2

Syntax highlighter might be an object literal with a method named all. This is generally done to organize functions into namespaces to avoid populating the global namespace. It might be defined as such: Check out this http://jsfiddle.net/PQbEU/2/

syntaxhighligter = {
    all: function(inputColor) {
        if (!inputColor) 
            inputColor= prompt("Enter a color");
        $('#all').css({
            background: inputColor
        });
    }
}
syntaxhighligter.all();​
SoWhat
  • 5,564
  • 2
  • 28
  • 59
1

From https://github.com/alexgorbatchev/SyntaxHighlighter/blob/master/scripts/shCore.js - it's a function which returns an object. It's a JavaScript code-organization pattern.

https://stackoverflow.com/a/1598077/18255

http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth

Community
  • 1
  • 1
Cade Roux
  • 88,164
  • 40
  • 182
  • 265