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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:53:40+00:00 2026-06-10T01:53:40+00:00

I am using John Resig’s Simple JavaScript Inheritance to create a class that can

  • 0

I am using John Resig’s “Simple JavaScript Inheritance” to create a class that can be inherited. I am also using KnockoutJS for computed observables. The problem comes in trying to combine these two concepts. When I try to gain a reference to self in the computed observable I get the “Window” object instead of the expected actual object. Here is a quick code sample:

window.mynamespace.myclass = Class.extend({
    init: function() {

    },
    someProperty: ko.observable(10),
    someComputedProperty: ko.computed(function() {
       return this.someProperty();  
    }, this)
});

Unforunately this.someProperty() is unable to be found because ‘this’ is a reference to Window. Any thoughts or ideas?

  • 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-10T01:53:42+00:00Added an answer on June 10, 2026 at 1:53 am

    You could always add them in the init. In knockout’s own examples they do their binding in the constructor.

    window.mynamespace.myclass = Class.extend({
        init: function() {
            this.someProperty = ko.observable(10);
            this.someComputedProperty = ko.computed(function() {
               return this.someProperty();  
            }, this);  
        }
    });
    

    Or capturing a reference to this and forgetting about binding:

    window.mynamespace.myclass = Class.extend({
        init: function() {
            var self = this;
            self.someProperty = ko.observable(10);
            self.someComputedProperty = ko.computed(function() {
               return self.someProperty();  
            });  
        }
    });
    

    Edit:

    To demonstrate how you’d extend the class:

    window.mynamespace.myotherclass = window.mynamespace.myclass.extend({
        init: function() {
          // do anything myotherclass init, like another observable
          this.someOtherProperty = ko.observable(10);
    
          // incidentally you *can* have private variables with this pattern
          var imPrivate = 1;
          this.getImPrivate = function() {
            return imPrivate;
          };
    
          // then call super (maybe with arguments, maybe just passing them)
          this._super('foobar');
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using John resig's implementation class mentioned here: http://ejohn.org/blog/simple-javascript-inheritance/ Now I have a
I'm using John Resig's excellent javascript class for simple javascript inheritance and I'm having
I have a custom Javascript class (created using John Resig's Simple Javascript Inheritance ).
I am using John Resig's Simple JavaScript Inheritance and have run into an issue
I decided to try out JavaScript genius John Resig's simple JavaScript inheritance as detailed
I am using John Resig's JavaScript class definition style . Below is an example
I'm using John Resig's recipe for JavaScript 'classes' and inheritance. I've stripped my code
I've been using John Resig's getStyle function from Pro JavaScript Techniques to get the
How can I modify John Resig's microtemplating engine so that it should not use
I'm reading the John Resig blog about the Strict Mode in javascript, but i

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.