"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Thursday, January 17, 2013

Extension Method In Javascript

Extension Method In Javascript



<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script type="text/javascript">
        String.prototype.IsFilled = function () {
            if (this && this.length > 0) {
                return true;
            }
            return false;
        }

        String.prototype.IsEmpty = function () {
            return !this.IsFilled();
        }

        Number.prototype.TripleSquare = function () {
            return Math.sqrt(this * this * this);
        }

        Number.prototype.AddDollar = function () {
            return '$' + this;
        }
        var name = "I'm Arun Aravind";
        var value = 20;
        document.write("name.IsFilled(): " + name.IsFilled());
        document.write("<br/>");
        document.write("name.IsEmpty(): " + name.IsEmpty());
        document.write("<br/>");
        document.write("2 Triple Square :" + value.TripleSquare());
        document.write("<br/>");
        document.write("add dollar sign :" + value.AddDollar());
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    </div>
    </form>
</body>
</html>

Output

















If u had any trouble just ask, Happy to help u :)
Stay Tune...
Have a nice day... 'N happy Coding :)

No comments: