Search

StringBuilder in JavaScript

a simple StringBuilder class that pushes individual strings into an array and then uses the join method to produce the concatenated output string.


Process Piping

This example shows the technique called as process piping. Process piping is a technique to redirect input/out form a process to get the result in runtime. This enable us to execute any process with a given set of parameters and capture the output. In the example below weare invoking the command shell(cmd.exe) to do a ping on "Bing.com" and capture the output in the console.



We can further create a function which does the same for us, and alter the behaviour by sending different parameters.

JavaScript AJAX wrapper

This is a simple code that wraps the XmlHttp Request and Response.

Class in JavaScript

As per Wikipedia: "JavaScript is classified as a prototype-based scripting language with dynamic typing and first-class functions. This mix of features makes it a multi-paradigm language, supporting object-oriented,[6] imperative, and functional[1][7] programming styles." But we still never explore the object orientation side of it, to start with.. we can create Class & Modules to divide the program in small chucks oflogic. This example shows you how to create a class in JavaScript.
As per the above code, we have defined a class which is actually a function since JScript don't have class keyword and a constructor(will be same as the class name). "this" refers to the current object in memory and the variable1 is prototyped to it.

Module in JavaScript

Javascript has always been written with a function oriented structure, as the script goes more dense it become complicate and harder to manage & extend. With Javascript module we can segregate these as logical modules. Here is an example how this can be done in JavaScript.

Fluent interface in C#

A fluent interface is normally implemented by using method cascading (concretely method chaining) to relay the instruction context of a subsequent call (but a fluent interface entails more than just method chaining [1]). Generally, the context is
1. defined through the return value of a called method
2. self-referential, where the new context is equivalent to the last context
3. terminated through the return of a void context.

So here it code how you can implement Jquery like fluent interface(method chaning) with C# code.


Here i have chained the method using a class called "FluentInterface", which implements the StringBuilder and provided a set of method, which are chained together. This implements JQuery like accessability in c#. The function can be called as:
 

 new FluentInterface().Add("line1").Add("line2").Replace("line2","line456").
Add("line3").Add("line4").Add("line5").Print().Clear();