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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:13:01+00:00 2026-05-25T14:13:01+00:00

This has been driving me crazy because I can’t find anything on Google. Maybe

  • 0

This has been driving me crazy because I can’t find anything on Google. Maybe it’s because I don’t know the right terminology to search right. But this is what I’m trying to do.

I want to create a function that acts like an object. I’m think it’s called a method, though I could be wrong.

Check this out, this is some pseudocode of what I would like it to do.

function myMethod(){
var p = this.getAttribute('x');
var p = p+1;
return p;
}

function otherFunction(){
var q = document.getElementByID('Element').myMethod();
alert(q);
}

So, I can’t get this to work. It keeps saying myMethod() is undefined and not a function.

  • 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-25T14:13:02+00:00Added an answer on May 25, 2026 at 2:13 pm

    If you want myMethod to be available on elements, you’d have to append it to elements’ prototype.

    Element.prototype.myMethod = myMethod;
    

    The concept of prototype is big, but it comes down to the fact that instances of functions have a function available in the way that you describe as ‘like an object’.

    In this case, any element on the page is an instance of the Element function. Therefore, any element will have .myMethod available, which you can call. (Element is a function although you don’t really deal with that – the instances are available because you put them there in HTML, so you bypass using Element.)

    Second, if you have var p, then another var p does not make much sense. Just use p = p + 1, or p++ (shortcut for adding one).

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

Sidebar

Related Questions

This has been driving be crazy, but I can't seem to find an answer.
This problem has been driving me crazy and Monday mornings don't really help. I'm
this has been driving me nuts because i know theres a simple solution but
This has been driving me crazy for the past 2 days, and anything close
This has been driving me crazy. I've done lots of google and stackoverflow searches
I hope someone can help me. This has been driving me crazy for days.
This has been driving me crazy for a few days. Why doesn't the following
This has been driving me crazy for the past few minutes I have a
This has been driving me crazy for the past couple of hours. I have
This has been driving me crazy for 2 days. I have been trying to

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.