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

Pages

Tuesday, January 8, 2013

Create Custom Class in javascript

First of all, i really doesn't know how it says.just name class :). On my R&D just tried and got this here i'm sharing that 



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

    <script type="text/javascript">
        function load() {
            var Agency = new function() {
                this.fname = "";
                this.lname = "";
                this.Street = "";
                this.country = "";
                this.website = "";
                this.AgencyDetail = function() {
                    return ' First Name :: ' + this.fname + ' \n Last Name :: ' + this.lname + ' \n Address :: ' + this.Street + ', ' + this.country + ' \n Website :: ' + this.website;
                }
            }

            Agency.fname = 'Arun';
            Agency.lname = 'Aravind';
            Agency.country = 'India';
            Agency.Street = 'Oyoor';
            Agency.website = 'www.simplyasp.blogspot.com';
            alert(Agency.AgencyDetail());
        }
        window.onload = load();
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
    </div>
    </form>
</body>
</html>


 and the Output looks 












This method is pretty helpful while looping in JavaScript and also for re-usability code too.

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

No comments: