Wednesday, August 28, 2013

JavaScript Patterns


1. Constructor Pattern for Creating Objects
function Fruit (theColor, theSweetness, theFruitName, theNativeToLand) {

    this.color = theColor;
    this.sweetness = theSweetness;
    this.fruitName = theFruitName;
    this.nativeToLand = theNativeToLand;

    this.showName = function () {
        console.log("This is a " + this.fruitName);

    this.nativeTo = function () {
    this.nativeToLand.forEach(function (eachCountry)  {
       console.log("Grown in:" + eachCountry);

var mangoFruit = new Fruit ("Yellow", 8, "Mango", ["South America", "Central America", "West Africa"]);
mangoFruit.showName(); // This is a Mango.
//Grown in:South America
// Grown in:Central America
// Grown in:West Africa
2. Prototype Pattern for Creating Objects
function Fruit () {

Fruit.prototype.color = "Yellow";
Fruit.prototype.sweetness = 7;
Fruit.prototype.fruitName = "Generic Fruit";
Fruit.prototype.nativeToLand = "USA";

Fruit.prototype.showName = function () {
console.log("This is a " + this.fruitName);
Fruit.prototype.nativeTo = function () {
            console.log("Grown in:" + this.nativeToLand);
var mangoFruit = new Fruit ();
mangoFruit.showName(); //
// This is a Generic Fruit
// Grown in:USA
JavaScript Patterns


  1. This blog is impressive and informative.It clearly explains about the concept and its techniques.Thanks for sharing this information.Please update this type of information
    informatica training in chennai

  2. It is really a great and useful piece of info. I’m glad that you shared this helpful info with us. Please keep us informed like this. Thank you for sharing.

    CRO Agency in Chennai

  3. Great post! I am actually getting ready to across this information, It's very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.

    digital marketing company in chennai
    seo company in chennai

  4. wow amazing post.The key points you mentioned here related to maintenance of car is really awesome.Checking all fluid levels,changing oil and of course the regular service of the car which is necessary to maintain our vehicle.Thank you for the information.

    car spa at doorstep in mumbai

  5. I think it's awesome someone is finally taking notice of our vet's and doing something to help them. I hope all goes well with these articles. More new information i will get after refer that post.
    Best Interior Designers in Chennai
    Interior Designers in Chennai

  6. There are many interesting information included and i can easily understand all given information.I post something on my blog to post something, or wait to post something worth saying. Keep update more information....
    Tax Accountant Melbourne
    Investment Advisor Melbourne
    Mortgage Broker
    Mortgage Broker Melbourne

  7. I think great site for these post and i am read the most of contents have useful for my Carrier.Thanks for these useful information.Any information are commands like to share him.

    Oracle Training in Chennai


  8. Its very useful to me. Wonderful blog.. Thanks for sharing informative Post.

    Installment loans
    Payday loans
    Title loans


  9. Its a wonderful post and very helpful, thanks for all this information. You are including better information regarding this topic in an effective way.Thank you so much

    Personal Installment Loans
    Title Car loan
    Cash Advance Loan

  10. Its a wonderful post and very helpful, thanks for all this information. You are including better information regarding this topic in an effective way.Thank you so much

    SEO Company in Chennai
    SEO Company in India
    Digital Marketing Company in Chennai
    Digital Marketing Company in India
    Web Development Company in India
    Web Design Company in Chennai