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 7004767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:14:29+00:00 2026-05-27T21:14:29+00:00

I’ve been learning Js recently from JavaScript the Good Parts , and according to

  • 0

I’ve been learning Js recently from “JavaScript the Good Parts“, and according to my understanding

Object.propertyName yields same result as Object["propertyName"](Please correct me if I’m not right and describe the difference of the two).

I’m trying to augment the Function.prototype to make a method available to all functions as below:

Function.prototype.method = function (name, func) {
            this.prototype[name]= func;
    };

And it’s working fine.However, when I’m replacing the this.prototype[name] with this.prototype.name, it’ll fail functioning as expected!

This is how I’m testing it:

 Number.method("myRoundFunction", function () {
        return Math[this < 0 ? "ceil" : "floor"](this);
    });
    console.log((-10 / 3).myRoundFunction());

This shows the expected value (-3) when using this.prototype[name], but

(-3.3333333333333335).myRoundFunction is not a function

on changing it to this.prototype.name

Could someone possibly clarify why this is happening?

Thanks in advance for any help.

  • 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-27T21:14:30+00:00Added an answer on May 27, 2026 at 9:14 pm

    What’s happening is that name is a variable, and cannot be used directly with dot notation. To better illustrate the issue, let’s say you pass a value of "newMethod" for name. Now when you do:

    this.prototype[name] = func;
    

    …it is equivalent to writing:

    this.prototype["newMethod"] = func;
    

    But when you do:

    this.prototype.name = func;
    

    …you are assigning to the name property of the object, and not to the newMethod property. The variable that you passed under the parameter name is not referenced at all in the above statement.

    The syntax that would preform the assignment you expect is:

    this.prototype.newMethod = func;
    

    But you cannot express that using dot notation and the name variable (except perhaps by cheating and using string concatenation and eval()). In such a case you have to use the array-subscript notation instead.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
i got an object with contents of html markup in it, for example: string

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.