Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8975473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:53:28+00:00 2026-06-15T18:53:28+00:00

I am learning the Javascript tips from this http://code.google.com/p/jslibs/wiki/JavascriptTips site. I came to see

  • 0

I am learning the Javascript tips from this http://code.google.com/p/jslibs/wiki/JavascriptTips site.

I came to see about the Factory method pattern. They shown the following example

Complex = new function() {

        function Complex(a, b) {
                // ...
        }

        this.fromCartesian = function(real, mag) {

                return new Complex(real, imag);
        }

        this.fromPolar = function(rho, theta) {

                return new Complex(rho * Math.cos(theta), rho * Math.sin(theta));
        }
}


var c = Complex.fromPolar(1, Math.pi); // Same as fromCartesian(-1, 0);

But I can’t guess why actually this is called as Factory method pattern. I want to know about this Factory method pattern and advantage of using this and especially to know where to exactly use this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T18:53:30+00:00Added an answer on June 15, 2026 at 6:53 pm

    The Factory pattern may be described as a function that creates a class instance (like a real factory produces cars or toys, etc.) In your example, Complex is a factory that can create instances in two ways: cartesian or polar.

    The Factory pattern is useful in a number of scenarios, including:

    • the Factory maintains information needed (such as a sequence number, or usually something more complex) for creating instances
    • the Factory maintains the instances over their lifetimes (such a pool of resources).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am learning javascript sample from this page, http://nofunc.org/AJAX_Star_Rating my questions are (1), for
I'm learning javascript. Poked around this excellent site to gather intel. Keep coming across
I am learning JavaScript from a book and in a code example that I
I am learning javascript sample from this page and I am using IE 7
I am learning javascript and I came across the following code snippet: var outerValue
Im learning javascript and I just dont understand what this javascript syntax actually means...
I'm only just learning javascript so I imagine this is relatively simple but it's
I've been learning JavaScript recently, and I've seen a number of examples (Facebook.com, the
Im just learning javascript and I'm just wondering why this doesn't work. I've created
I am learning JavaScript through Codecademy, but I have an issue. The code below

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.