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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:28:02+00:00 2026-05-27T04:28:02+00:00

In Ruby, you can capture a call to a method which is missing and

  • 0

In Ruby, you can capture a call to a method which is missing and define it on the fly.

What I wanna accomplish in JavaScript is to have an object with no methods. I want a missing method to be translated into a call to emit():

app.isReady() -> app.emit("isReady")
soldier.kills() -> soldier.emit("kills")

I think it’s better to capture the missing method error and run emit(methodName) rather than defining all methods (from a fixed list) at runtime. That way we don’t have performance overhead if there are hundreds or thousands of events for an object.

What is the best way to do this?

UPDATE: This is an API design so I rather stay out of:

try {
  app.isReady()
} catch(e) {
  ...
}

I want to know how I can accomplish this behind the scenes so the users can use methods as usual.

  • 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-27T04:28:03+00:00Added an answer on May 27, 2026 at 4:28 am

    In that way we don’t have a performance overhead if there are hundreds/thousands of events for an object.

    I think it’s a massive misconception to think the performance overhead of adding methods to an object is smaller then the performance overhead of converting method invocations into emit calls.

    However you cannot implement this feature in ES5

    One could however implement this using Harmony proxies.

    I recommend looking at simulating __noSuchMethod__.

    I believe ES6 proxies are experimental and can be turned on in V8 so you could use them with node.js today.

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

Sidebar

Related Questions

Ruby can add methods to the Number class and other core types to get
How can I do the Ruby method Flatten Ruby Method in C#. This method
Can Ruby 1.9.1 finally get a list of filenames if the filenames have unicode
in ruby you can have: class ApplicationController < ActionController::Base before_filter :require_login end i just
I am trying to write a Ruby regex which would capture quoted phrases apart
When you use a system call in a Ruby script, you can get the
I think I've found something which C# and Ruby can do but Python can
I have a small ruby app in which I'm trying to query some information
I know in Ruby can add and modify method of class dynamically in run
In Ruby you can reference variables inside strings and they are interpolated at runtime.

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.