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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:18:58+00:00 2026-05-26T20:18:58+00:00

I need something like so function updateRender(ClassName){ if(!(this.currentRender instanceof ClassName)){ doPreprocessing(); this.currentRender = new

  • 0

I need something like so

function updateRender(ClassName){
   if(!(this.currentRender instanceof ClassName)){
         doPreprocessing();
         this.currentRender = new ClassName();
         doPostProcessing();
   }
}

So I would be able to call updateRender with a new render object, which can be different type.

updateRender( SolidRender );
updateRender( HollowRender );
updateRender( HollowRender ); //does nothing because currentRender is HollowRender
  • 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-26T20:18:59+00:00Added an answer on May 26, 2026 at 8:18 pm

    You’ve already got your answer in the comments, so this is just an FYI:

    You’re using this.currentRender, which – if the function is in the global scope – will refer to a variable the global scope. I.e. to the window object of the browser. And putting things in global scope is very rarely a good idea.

    Technically, you should put all your code in a single namespace or even inside a function that’s invoked immediately so it doesn’t pollute the global scope. However, you can start by simply getting the currentRender variable out of the global scope by doing this:

    var updateRender = (function () {
        var currentRender = null;
    
        return function (klass) {
            doPreprocessing();
            currentRender = new klass();
            doPostProcessing();
        };
    
    }());
    

    the updateRender function will still be in the global scope, but at least the currentRender variable is safely hidden inside a closure, so only updateRender can change it (aka privileged access).

    As for using klass instead of Class, that’s entirely up to you. Using klass is just a common way of getting around the “class is a keyword” problem in Ruby.

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

Sidebar

Related Questions

What I need is something like this: /<[\w\d]+ ([\w\d]+\=[w\d])+\/>/ Something that would match several
I need something like this http://jonraasch.com/blog/a-simple-jquery-slideshow but w/o the absolute positioning. Is it possible?
Ok, I need something like this: datediff(second, date_one, date_two) < 1 dates are stored
I need to do something like this: <input type=button value=click id=mybtn onclick=myfunction('/myController/myAction', 'myfuncionOnOK('/myController2/myAction2', 'myParameter2');',
I think I need something like ruby's splat * here. function foo() { var
How can I declare a function inside GSP? I need something like taglib but
I need to call a function on a using jquery. This function needs to
Inside a Matlab function I need something like (as you can imagine in real
I need something like the C function getservbyname() for a Java application. I've got
How to send a table to function as argument? Need something like that: CREATE

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.