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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:00:01+00:00 2026-05-26T22:00:01+00:00

Just experimenting with different inheritance techniques in JS, and came across something mildly discomfiting

  • 0

Just experimenting with different inheritance techniques in JS, and came across something mildly discomfiting about Crockford’s Prototypal Inheritance pattern:

function object(o) {
    function F() {}
    F.prototype = o;
    return new F();
}

var C,
    P = {
         foo:'bar',
         baz: function(){ alert("bang"); }
         }

C = object(P);

It’s all good – except when you log to console – the object appears as F. I’ve seen classical emulation in which you can repoint the constructor – is there a similar method to coerce the objects (console) reference?

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

    The issue is that it’s referring to the name of the constructor function. This quickly becomes a discussion about function expressions and statements and the name property. Turns out is is completely impossible to create a new named function at runtime without using eval. Names can only be specified using a function statement function fnName(){} and it’s not possible to construct that chunk of code dynamically aside from evaling it. var fnExpression = function(){} results in an anonymous function assigned to a variable. The name property of functions is immutable so it’s a done deal. Using Function("arg1", "arg2", "return 'fn body';") also only can produce an anonymous function despite being similar to eval.

    It’s basically just an oversight in the JS spec (Brendan Eich stated he regrets defining the display name the way he did 10 or so years ago) and a solution is being discussed for ES6. This would introduce more semantics for deriving a function’s display name for debug tools or perhaps an explicit way to set and adjust it.

    For now you have one route: eval, or some other form of late execution of configurable code. (eval by any other name…)

    function displayName(name, o){
      var F = eval("1&&function "+name+"(){}");
      F.prototype = o; 
      return new F;
    }
    

    The function statement alone won’t return from eval, but doing 1 && fnStatement coerces the thing into an expression which is returnable.

    (Harmony Proxies also allow setting up functions that report names which you can configure without eval but that’s not usable except in Node.js and Firefox currently).

    I’ll make a note here that all those “evil” functions that have been shat upon by Crockford and many others ALL have their place. eval, with, extending natives all enable specific techniques which are otherwise completely impossible and it’s not wrong to use them when the occasion is right. It’s just likely that most people aren’t qualified to make the judgement of when that time is right. In my opinion using eval harmlessly to make up for poor language semantics and tools while waiting for a solution is perfectly acceptable and won’t cause you any harm as long as you’re not funneling arbitrary code into that eval statement.

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

Sidebar

Related Questions

I've just been experimenting with the boost::function_types library recently, and I've come across a
I am just experimenting something with jQuery. I have an image which fades into
I'm just starting out with Python and experimenting with different solutions. I was working
I'm just experimenting with boost::pool to see if its a faster allocator for stuff
I just started experimenting with Aptana Jaxer server side javascript engine for my next
I've just started experimenting with SDL in C++, and I thought checking for memory
I've just started experimenting with WPF templates vs. styles and I'm not sure what
Hi I've just started experimenting with .live and .die and having some great results
I've just been experimenting with a CSS tooltip that fades in with CSS3's transitions.
I've been searching and experimenting for nearly four hours now, so I'm gonna just

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.