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

  • Home
  • SEARCH
  • 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 652745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:18:22+00:00 2026-05-13T22:18:22+00:00

So, I was reading up on John Resig’s blog , saw his micro-templating javascript

  • 0

So, I was reading up on John Resig’s blog, saw his micro-templating javascript engine and decided to try and implement my own template management system for javascript, to deepen my understanding of prototype inheritance. However, the minute I started writing it, I ran into a problem.

To start off, here is my base code:

function template_manager() { };

template_manager.prototype = {
    tags: {},
    templates: {},
    output: {},
    default_template: "default",
    set: function (tags, template_name) {
        template_name = "Greetings!";
        //template_name = this._util.template(this.nothing, this.default_template);
        console.log(template_name);
    },
    get: function(tags, template_name) {
        console.log("Getting");
    },
    unset: function(tags, template_name) {
        console.log("Removing");
    },
    render: function(template_name) {
        console.log("Rendering");
    },
    //_util goes here
};

// Take it for a quick test drive.
test = new template_manager;
test.set();
test.get();
test.unset();
test.render();

Then I started working on some common code, and I decided to put it into a utility object:

    _util: {
        // Used to set the default values for optional arguments
        optional: function(obj, def_value) {
            return (typeof obj === "nothing") ? obj : def_value;
        },
        template: function(template_name) {
            return this._util.optional(template_name, this.default_template);
        },
    },

And now, when I try to call my _util.template() function in my set() function I of course get an error because this points to the _util object rather than the template_manager object. I’ve take a look at the jQuery extend method, and I think that I understand what it’s doing. My question is, do I need to implement my own / use jQuery’s extend method, or is there another way for me to call the template_manager object from my _util object?

(P. S. I’ve looked at Douglas Crockford’s article on prototype inheritance, and I think the answer is there, but I’m afraid I don’t fully understand it yet.)

  • 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-13T22:18:22+00:00Added an answer on May 13, 2026 at 10:18 pm

    You can use call or apply i.e.

    template_manager.prototype = {
        set: function (tags, template_name) {
            template_name = "Greetings!";
            template_name = this._util.optional.call(this, this.nothing, this.default_template);
            console.log(template_name);
        }
    }
    

    See “Getting Out of Binding Situations in JavaScript” article for more explicit explanation.

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

Sidebar

Related Questions

I was reading John Resig's Secrets of JavaScript Ninja and saw this code: function
I'm reading the John Resig blog about the Strict Mode in javascript, but i
I am a newbie to java script and currently reading John Resig's Pro javascript
I m reading John Resig s Learning Advanced JavaScript http://ejohn.org/apps/learn/#10 and came across this
I was reading John Resig's article about JavaScript Getters and Setters when I found
I am reading the book Secrets of the JavaScript Ninja by John Resig and
Reading manual about Sling http://sling.apache.org/site/46-line-blog.html added folder blog and blog.html to destination: \launchpad\content\src\main\resources\content\ but
I'm attempting to learn some flex/bison, and I'm reading Flex & Bison by John
I've been reading a lot on TDD over the past few months and decided
I have been reading John R. Levine's Linkers and Loaders and I read that

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.