Contents tagged with Javascript

  • TypeScript notes

    Hello everybody,

    today I want to make some notes of type script, or if to spell it correctly TypeScript.

    So, few words about TS.

    File extensions for TypeScript is .ts. 

    TypeScript is superset of javascript which means that TypeScript understands javscript code. Also for execution TypeScript gots trasplied to javascript. 

    What means transpilation? If to take analogy from C#, it looks like this:

    wonderfulProgram.cs -> C# compiler -> wonderfulProgram.dll 

    Now let compare it with TypeScript:

    wonderfulProgram.ts -> TypeScript compiler ->  wonderfulProgram.js

    Another important part of TypeScript is strong typing:

    JavaScript

    TypeScript

    var x;

    x = 67;

    x='some string'

    x = … more

  • SVG drawings

    Hello everybody.

    Today I want to share with you simple way to draw Mutual Style Fund box with help of javascript and svg in html5 with usage of module pattern of javascript. 

    Recently I had task to make at web site drawings with javascript. After some research I decided to use javascript and svg. Here is screenshot of result:

    You can choose scaling size and row and column to display.

    Here it goes html code:

    <!DOCTYPE html>

    <html>

    <head>

    <title></title>

    <meta charset="utf-8"/>

    <script src="Scripts/jquery-1.10.2.js"></script>

    <script src="Scripts/MorningStar.js"></script>

    </head>

    <body>

        <script type="text/javascript">

            function Display() {

                var  … more

  • Module and revealing module design patterns in Javascript

    Hello everybody,

    today I want to propose you interesting comparison of two design patterns in javascript.  As you probably know, javascript doesn't have idea of public and private members. So in order to implement them some tricks are used. That is module and "revealing module".

    Take a look at samples of them:

    Module

    Revealing module

    var md = ( function(){

     var privateMember = “private”;

    return {

                publicMember : “publicMember”

            };

    }

    )();

    var md = ( function(){

     var privateMember = “private”;

     var publicMember = “publicMember”;

    return {

                publicMember : “publicMember”

    };

    }

    )();

    The difference is where are … more

  • Spies and secret agents in javascript

    Hello everybody,

    Have you ever had a desire to become chief of secreat agent or spy? To be honest I never had such desire, but unwilignly I become chief of spies  and secret agents which I created in javascript. 

    To put simply during unit testing of javascript sometime is needed to mock calling to some functions with replacement of that function, and sometime there is a need to mock that function without it's replacement. 

    The first scenario is much easier to implement, while the second one required usage of apply function. 

    Take a look at the following picture:

    There are many js libraries which support both options ( with and without original function ). For example jasmine, … more

  • How to define properties in javascript

    Hello everybody,

    here is short notice of how to define properties in javascript:

    So, lets say you want to have class Dog, with "private" field alias and public property Alias. you can achieve it in the following way:

    function Dog(nameOfDog) {

        var alias = nameOfDog;

        Object.defineProperty(this, "Alias", {

                get: function() {

                    return alias;

                },

                set: function(value) {

                    alias = value;

                }

            }

        });

    }

    Later in code you can write the following:

    var rex = new Dog("Rex");

    var name = rex.Name;   // name will be equal to "Rex"

    Also you can set name of the dog to other name. 

    more