One interesting aspect of Javascript is its prototype support, which can be used in a similar manner to classes in the C# world.
// Here's an example defining a constructor for a class named "ABC"
function ABC() {
this.name = null;
}
// Creating an instance of the class
var obj = new ABC();
// Checking the value of the instance property
console.log(obj.name); // This will output "null"
// Setting the value of the instance property
obj.name = "something";
// Some more checks
console.log(obj.name); // Now it will display "something"
console.log(obj); // Outputting the entire object
When it comes to public and internal/private classes, they can be somewhat replicated within function scope in Javascript. Unlike C#, which has block scope, Javascript only has function scope.
Developers often encapsulate client logic inside a function to create a private scope, preventing any conflicts with public names or exposing internal functionality. This way, they can selectively make certain elements available in the public scope.
A good example of this pattern is seen in popular client libraries like jQuery or AngularJS. These libraries have extensive internal logic but only expose a limited number of publicly accessible functions (such as the angular
variable in AngularJS).