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

  • Home
  • SEARCH
  • 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 5998941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:28:37+00:00 2026-05-23T00:28:37+00:00

I am trying to learn the real nitty gritty details of Javascript, so I

  • 0

I am trying to learn the real nitty gritty details of Javascript, so I would appreciate it if someone could explain this code for me. In ColorBox, the author defines his public method as so:

publicMethod = $.fn[colorbox] = $[colorbox] = function (options, callback) {
    // do stuff...
};

Other public methods are then defined such as:

publicMethod.remove = function () {
    // do more stuff
};

In practice, I know that these function can then be called as $.colorbox() and $.colorbox.remove(), but I’m a little confused by the actual syntax. Specifically, what is happening when he assigns “$.fn[colorbox]” and “$[colorbox]” to publicMethod?

Do you have any commentary on this code? Is this a good design pattern? Are there other patterns you would recommend?

  • 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-05-23T00:28:38+00:00Added an answer on May 23, 2026 at 12:28 am

    In JavaScript each object is an associative array at the same time, object properties are also array keys. This means that obj.prop = 1 and obj["prop"] = 1 are exactly the same thing. Also, methods are simply properties that have a function as their value. So $["colorbox"] = function() {...} creates an anonymous function and assigns it as property colorbox of the object $ ($ is a regular variable name in JavaScript), this function becomes method $.colorbox() then. Note that I used the string "colorbox", your code example has it without quotation marks however – which would interpreted as a variable name, so a variable colorbox with the value "colorbox" is probably used there.

    Functions are objects as well so you can set custom properties on them. In the example the property remove is being set on the function object and becomes its method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to learn C++ so forgive me if this question demonstrates a lack
I am trying to learn OOP. The so called 'real world' examples in the
I'm currently trying to learn regular expressions with some simple "real world" examples. Take
Disclaimer: I'm trying to learn proper OO programming/design, so I'm pretty new to this
Continuing roadblocks when trying to learn Haskell. I am following the Real World Haskell
Im trying to learn OOP but I need to see some real case scenarios
I don't really have a real world problem, yet, but I'm trying to learn
This is a noob question. I'm trying to learn how to use SWIG to
Trying to learn a bit of CSS and I want a horizontal navbar and
In trying to learn how to create objects in ActionScript, I have had no

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.