Java Script Hidden Function
A couple of things, first I cleaned up your JS a bit and encapsulated your null check in a method. I also added the missing markup elements which I assume were omitted on accident from your OP.
Here is a fiddle: http://jsfiddle.net/gev4kwnf/5/
The JavaScript now looks like this:
function setVisible(id, visible) {
var o = document.getElementById(id); //get the element based on it's id
//if the element exists then set it's visiblity
if (isElement(o)) {
o.style.visibility = visible ? 'visible' : 'hidden';
} else {
alert("Element with id '" + id + "' not found.");
}
}
function setDisplay(id, visible) {
var o = document.getElementById(id);
if (isElement(o)) {
o.style.display = visible ? 'block' : 'none';
} else {
alert("Element with id '" + id + "' not found.");
}
}
function isElement(obj) {
var returnValue = false;
if (obj == undefined || obj == null) {
returnValue = false;
} else {
returnValue = true;
}
return returnValue;
}
Javascript FAB framework on Node.js
Is plain JavaScript, it is a function chaining pattern.
The first line, ( fab = require("fab") )
includes the fab
function and returns a reference to it.
All the subsequent parentheses are function calls, each function invocation returns probably the same function again and again.
The pattern probably looks like this simplified example:
var foo = function (arg) {
// detect what the argument is
if (typeof arg == 'function') {
// do something with arg
console.log('function: '+arg());
} else if (arg instanceof RegExp) {
// arg is a RegExp...
console.log('A RegExp: '+arg);
} else if (typeof arg == "string") {
// arg is a string
console.log('A string: '+arg);
}
return foo; // return a reference to itself
};
(foo)
(function() { return "Foo "; })
(/bar/)
(" baz!");
Outputs:
function: Foo
A RegExp: /bar/
A string: baz!
Features of JavaScript that C developers fail to take advantage of?
It's mainly an issue with writing procedural code in JavaScript. You'll miss out on two big features if you write JavaScript like C :
Prototypical OOP and First class functions
Prototypical OOP allows you to create new objects and apply many of the OOP patterns of other languages. It's rather different from classical OOP.
A good article on that would be JavaScript Garden Objects section
First class functions allow you to pass functions as arguments and this allows you to write functional code. With just this alone you can get close to the power of LISP, ML or Haskell. Again a good article is JavaScript Garden Functions section.
The reason why these two things are big is because they allow you to use the OOP paradigm and the Functional paradigm.
Otherwise you will be stuck writing Procedural JavaScript forever.
Related Topics
Passing Environment-Dependent Variables in Webpack
What's the Best Way to Convert a Number to a String in JavaScript
How to Add External Js Scripts to Vuejs Components
What Does = +_ Mean in JavaScript
Best Way to Iterate Over an Array Without Blocking the Ui
Are Eval() and New Function() the Same Thing
Defining Methods via Prototype VS Using This in the Constructor - Really a Performance Difference
Variable as the Property Name in a JavaScript Object Literal
Is There Any Non-Eval Way to Create a Function with a Runtime-Determined Name
How to Convert an Array of Objects to Object with Key Value Pairs
How to Automate Shadow Dom Elements Using Selenium
Copy Array Items into Another Array
Nodejs VS Node on Ubuntu 12.04
How to Convert Url Parameters to a JavaScript Object
What Is the Shortest Function for Reading a Cookie by Name in JavaScript