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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:06:24+00:00 2026-06-02T17:06:24+00:00

I don’t really get the function of ember.js’ reopenClass. I thought it added extra

  • 0

I don’t really get the function of ember.js’ reopenClass. I thought it added extra code to the Object’s prototype, so all instances of that Object would get the functionality that was added in a non static way. It does not do this however. It looks like it only adds code that can be statically executed. For instance. I have this code:

Logger = Ember.Object.extend({ 
  log: function(thing) { 
     console.log(thing + ' wassup'); 
    }
});

var logger = Logger.create();
logger.log("1, yo")

logger.reopen({ 
  log: function(name) { 
      console.log(name + 'ghurt')
    }
});
logger.log("2, yo")

Logger.reopenClass({ 
  log: function(name) { 
      console.log(name + 'fresh')
    }
});
logger.log("3, yo")
Logger.log("4, yo")

It outputs this:

1, yo wassup
2, yoghurt
3, yoghurt
4, yofresh

What I expected was this:

1, yo wassup
2, yoghurt
3, yofresh
4, undefined (I think)

So my question is: What does reopenClass do and when do I use it?

  • 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-02T17:06:25+00:00Added an answer on June 2, 2026 at 5:06 pm

    In general, reopen adds methods and properties to instances whereas reopenClass adds methods and properties to classes.

    The corresponding tests are ember-runtime/tests/system/object/reopen_test.js and packages/ember-runtime/tests/system/object/reopenClass_test.js.

    I’ve updated your code and added some comments, see http://jsfiddle.net/pangratz666/yWKBF/:

    Logger = Ember.Object.extend({
        log: function(thing) {
            console.log(thing + ' wassup');
        }
    });
    
    var logger1 = Logger.create();
    var logger2 = Logger.create();
    
    // instances of Logger have a 'wassup' method
    try { Logger.log("1, yo"); } catch (e) {} // Object (subclass of Ember.Object) has no method 'log'
    logger1.log("1, yo"); // 1, yo wassup
    logger2.log("1, yo"); // 1, yo wassup
    
    console.log('----');
    
    // overwrite log of concrete logger instance logger1
    logger1.reopen({
        log: function(name) {
            console.log(name + ' ghurt');
        }
    });
    
    try { Logger.log("1, yo"); } catch (e) {} // Object (subclass of Ember.Object) has no method 'log'
    logger1.log("2, yo"); // 2, yo ghurt
    logger2.log("2, yo"); // 2, yo wassup
    
    console.log('----');
    
    // classes of Logger have a 'fresh' method
    Logger.reopenClass({
        log: function(name) {
            console.log(name + ' fresh');
        }
    });
    
    Logger.log("3, yo"); // 3, yo fresh
    logger1.log("3, yo"); // 3, yo ghurt
    logger2.log("3, yo"); // 3, yo wassup
    
    console.log('----');
    
    // new* instances of Logger have from now on a 'dawg' method
    // * this will likely change in the future so already existing instances will reopened too
    Logger.reopen({
        log: function(name) {
            console.log(name + ' dawg');
        }
    });
    
    Logger.log("4, yo"); // 4, yo fresh
    logger1.log("4, yo"); // 4, yo ghurt
    logger2.log("4, yo"); // 4, yo wassup
    Logger.create().log("4, yo"); // 4, yo dawg
    
    console.log('----');
    

    ​

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

Sidebar

Related Questions

Don't get me wrong, I want them to get saved. But I always thought
Don't let below code scare you away . The question is really simple, only
Don't be scared of the extensive code. The problem is general. I just provided
Don't really know how to formulate the title, but it should be pretty obvious
I don't know whether this is really possible, but I'm trying my best. If
Don't know how to explain it better but i'm trying to get a response
Don't be frightened, its a very basic code. Just wanted to check with you
Don't they both have to convert to machine code at some point to execute
Don't have much to say, just can get into the event handler. XAML: <Grid>
Don't these two mean the same thing, first get the value and then increment?

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.