JavaScript: Difference between revisions
m →FAQ |
|||
Line 42: | Line 42: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== Check existence of variable == | === Check existence of variable === | ||
Can you check on the existence of a variable/object? | Can you check on the existence of a variable/object? | ||
* Yes, see example | * Yes, see example |
Revision as of 12:41, 30 May 2018
Always I can not find a pleasant and good reference/example of JavaScript code [1], but constant searching helps [2].
Documentation
Not a beginners guide and note a reference. JavaScript Garden (Bonsai Garden) is a growing collection of documentation about the most quirky parts of the JavaScript programming language. It gives advice to avoid common mistakes and subtle bugs, as well as performance issues and bad practices, that non-expert JavaScript programmers may encounter on their endeavours into the depths of the language. [2]
JavaScript Garden does not aim to teach you JavaScript. Former knowledge of the language is strongly recommended in order to understand the topics covered in this guide. In order to learn the basics of the language, please head over to the excellent guide on the Mozilla Developer Network.
Cookies
See for a description on how to cope with JavaScript Cookies
- JavaScript Cookies description
FAQ
My personal list of FAQ's.
Javascript function Name
How to het the function name of the function you are in. [3]
- Use: arguments.callee.name
- Example (code snippet):
<syntaxhighlight lang="javascript"> var logFormatLBW = '[%-25.25s] - %-15s %s';
function getTail() {
... m = arguments.callee.name; console.log(sprintf( logFormatLBW, m, 'callee' , arguments.callee.name));
</syntaxhighlight>
Default parameter
Is it possible to have a function with a default parameter?
- Yes, see example.
<syntaxhighlight lang="javascript"> /** Does something foo... @param string optionalParameter [Optional] option for .... [default: ""]
- /
function foo( optionalParameter ) {
var option = typeof optionalParameter !== 'undefined' ? optionalParameter : "";
} </syntaxhighlight>
Check existence of variable
Can you check on the existence of a variable/object?
- Yes, see example
<syntaxhighlight lang="javascript"> if ( somecondition) {
var newObject = { name: "myname, ... };
}
if ( typeof newObject !== 'undefined') {
newObject.method();
} </syntaxhighlight>
Links
- A list of FAQs, Index to a bunch of items.
Redirector
use the lcation object. An example:
<html> <title>CodeAve.com (JavaScript: Current Page URL)</title> <body bgcolor="#FFFFFF"> ... <script language="JavaScript"> <!-- document.write (location.href); document.write ("<p><a href='" +location.href + "'>Link To Current Page</a></p>"); // --> </script> ... </body> </html>
See also
- JavaScript Widgets and Games, mredkj.com is an unfocused resource for programmers in which you'll find code examples, tutorials, and our ramblings.
- JavaScript entry on HF-Links.
- Developer Mozilla, JavaScript Guide Developer.
- Developer Mozilla, JavaScript Reference
- Developer Mozilla, RegEx Reference
- krook.org JavaScript DOM
Reference
- ↑ JavaScriptKit, Index, Tutorials and Reference. This is a very good start.
- ↑ 2.0 2.1 Bonsai Garden, Javascript Examples, Best practices and tutorials.
- ↑ Kangax, Named function expressions demystified.