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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:33:17+00:00 2026-06-12T03:33:17+00:00

Have a look at this snipped: There is a transformator with a transformMap() -method.

  • 0

Have a look at this snipped:

There is a transformator with a transformMap()-method. This method calls two other methods of the transformator: transformMapHead() and transformMapBody()

transformator

var transformator =
{
    transformMap: function(tree) {
        return transformator.transformMapHead(tree)
              +transformator.transformMapBody(tree.body[0].body) +"}\n";
    },  

    transformMapHead: function(tree) { 
        return "to be done"; 
    },

    transformMapBody: function(tree) { 
        // completly implemented
    },  
    ...
};

Ok, fine so far.
The transformMapBody()-method is completly implemented, the transformMapHead()-method isn’t, this will be done in a child-object.

Now, lets have a look at a more concrete transformator. Here I only want to implement the transformMapHead()-method.

But, when I implement the

concreteTransformator

var concreteTransformator = Object.beget(transformator);                            

concreteTransformator.transformMapHead = function(tree)
{
    // my business logic
    console.log("i am the new business logic");
};

it doesn’t work correctly. Instead of running the transformMapHead()-method from the concreteTransformator-object, the method from the first transformator-object is executed and “to be done” ist printed out.

I can avoid this by copying the transformMap()-method from the transformer-object to the concreteTransformer-object:

concreteTransformator.transformMap =  function(tree) {
    return concreteTransformator.transformMapHead(tree)
          +concreteTransformator.transformMapBody(tree.body[0].body) +"}\n";
};

Then, everything runs fine, but this cannot be the way to go?!

At last, the beget-helper-function from Douglas Crockford:

if (typeof Object.beget !== 'function') {
Object.beget = function(o) {
    var F = function() {};
    F.prototype = o;
    return new F();
};

}

  • 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-12T03:33:18+00:00Added an answer on June 12, 2026 at 3:33 am

    The problem is that you are referencing a specific variable inside transformMap (transformator), which contains a reference to the original object. To understand the implications, consider what would happen if you did:

    var foo = transformator;
    transformator = null;
    foo.transformMap();
    

    You would get an error because transformator is null now and therefore does not have a property transformMapHead anymore.


    You should be using this instead:

    return this.transformMapHead(tree)
           +this.transformMapBody(tree.body[0].body) +"}\n";
    

    to refer to the current object.

    Learn more about this.

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

Sidebar

Related Questions

Have a look at this picture alt text http://www.abbeylegal.com/downloads/2009-04-01/web%20part%20top%20line.jpg Does anyone know what css
Have a look a this simple example. I don't quite understand why o1 prints
Have a look at this jsfiddle: http://jsfiddle.net/Dh96F/1/ The Expand button will animate the widening
Please have a look at this form that I am trying to design with
Please have a look at this page www.pixeli.ca/issue. I have begun making a page
Please have a look at this demo page that I cooked up a while
Please have a look at this validation array in my cakephp app for model
Let's have a look at this HTML code: <!DOCTYPE html> <html> <head> <title>Test</title> </head>
I have cells that look like this, one per line: Duffy,John: 'Heritage: Civilization and
I have a problem with internet explorer 6 and 7, please look this example

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.