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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:50:06+00:00 2026-05-26T03:50:06+00:00

I was using a custom made object handling library (for exams, can’t use things

  • 0

I was using a custom made object handling library (for exams, can’t use things that I don’t program personnaly, ie JS.class) which tends to break scope of functions.

File base.js

/**
 * Module internals
 */
function _add() {
    var obj_out = arguments[0];
    for (var i=1; i < arguments.length; i++) { var arg = arguments[i];
        for(prop in arg) { obj_out[prop] = arg[prop]; }
    };
    return obj_out;
}
function _merge() {
    var obj_out = {};
    for (var i=1; i < arguments.length; i++) { var arg = arguments[i];
        for(prop in arg) { obj_out[prop] = arg[prop]; }
    };
    return obj_out;
}
function _args(args) {
    return Array.prototype.slice.call(args, 0);
}
function _filterProps(items, re) {
    console.log("Items: ", items);
    var obj_out = {};
    console.log("Before: ", obj_out);
    var keys = [];
    for(var key in items) {
        keys.push(key);
    }
    console.log("Keys: ", keys);
    for (var i=0; i < keys.length; i++) { var key = keys[i];
        if(!re.test(key)){
            obj_out[key] = items[key];
            console.log("Step: ", obj_out);
        }
    }
    console.log("After: ", obj_out);
    return obj_out;
}

/**
 * Class declaration
 * Usage:
 {
    $extends: <classe parente>
    $include: [<modules>]
    $new: <constructeur>
    $static: <methodes statiques>
    $methods: <methodes>
 }
 */
exports.Class = function(items) {
    var base = !items["$extends"] ? Object.prototype : items["$extends"].prototype;
    var incs = !items["$include"]? [] : items["$include"];
    var stat = !items["$static"] ? {} : items["$static"];
    var meth = !items["$methods"] ? {} : items["$methods"];
    var cons = !items["$new"] ? function(){} : items["$new"];
    var left = _filterProps(items, /^\$/);

    var cls = function() {
        console.log("Constructor");
        console.log(arguments);
        cons.apply(this, _args(arguments));
    };
    cls = _add(cls, stat);
    cls.prototype = base;
    for (var i=0; i < incs.length; i++) {
        _add(cls.prototype, incs[i]);
    };
    _add(cls.prototype, left);
    _add(cls.prototype, meth);

    return cls;
}

File test.js

Base = require('./base');

var SomeClass = Base.Class({
    $new: function() { console.log("new"); },
    foo: function() { console.log("foo"); },
});

var OtherClass = Base.Class({
    $new: function() { console.log("new"); },
    bar: function() { console.log("bar"); }
});

console.log("SomeClass: ", SomeClass.prototype);
console.log("OtherClass: ", OtherClass.prototype);

Output of “node test.js”

Items:  { '$new': [Function], foo: [Function] }
Before:  {}
Keys:  [ '$new', 'foo' ]
Step:  { foo: [Function] }
After:  { foo: [Function] }
Items:  { '$new': [Function], bar: [Function] }
Before:  {}
Keys:  [ '$new', 'bar', 'foo' ]
Step:  { bar: [Function] }
Step:  { bar: [Function], foo: [Function] }
After:  { bar: [Function], foo: [Function] }
SomeClass:  { foo: [Function], bar: [Function] }
OtherClass:  { foo: [Function], bar: [Function] }

The _filterProps function tends to retain some values in its “for..in” loop and I can’t tell why. And I’m a little lost because javascript is not my forte.

My node version is v0.5.8-pre on Max OSX 10.6

Edit

Well thanks to Zack Bloom and his ability to see hidden bugs, I discovered that I forgot to copy the “Object.prototype” object so it was referencing it.

Thanks, JD

  • 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-26T03:50:07+00:00Added an answer on May 26, 2026 at 3:50 am

    It looks like you are extending Object.prototype, which will change all objects.

    base = Object.prototype
    cls.prototype = base
    _add(cls.prototype, ...)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made a custom handler that derives from MvcHandler. I have my routes using
I'm using custom WordPress categories for some probably unintended functions, I will admit (things
I am using custom model binder in ASP.NET MVC 2 that looks like this:
I've made a custom DataGridViewCell that displays a custom control instead of the cell;
I'm using some reflection to set up a ListView made up of custom views.
I want to pass a custom made vector object containing data from background service
I have a controller that makes HTTP GET requests using a custom class, which
When using custom template for Login control , if we add control with ID
When using custom assemblies in a visual studio project. How does one check in
Background : I am currently using custom controls within my C# project (basic controls

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.