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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:40:04+00:00 2026-06-08T15:40:04+00:00

implement change prototype, so why not just directory change it with ‘some class’.prototype…, It

  • 0

implement change prototype, so why not just directory change it with ‘some class’.prototype…, It seems very useless or palaver

  • 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-08T15:40:07+00:00Added an answer on June 8, 2026 at 3:40 pm

    There are two aspects to implement. In a Class context and on Objects (Types/Natives).

    Common benefits

    Common between them is, they are API. Because it’s API, MooTools can add ways that ensure that you don’t (accidentally) overwrite prototype methods that are protected on various Native types. See this bit which forces protection for many native methods: https://github.com/mootools/mootools-core/blob/master/Source/Core/Core.js#L238-282

    Also, implement is overloaded – which means you can pass on an object that implements more than one method at the same time, rather than break and have a new line for each prototype call.

    Function Methods in Classes are wrapped.

    These decorators are available:

    Function.implement({
    
        hide: function(){
            this.$hidden = true;
            return this;
        },
    
        protect: function(){
            this.$protected = true;
            return this;
        }
    
    });
    

    This means you can do

    Obj.implement({
       foo: foo.hide(),
       bar: bar.protect()
    });
    

    This allows you to have non-wrapped methods via .hide() to add properties that are not wrapped:

    Number.prototype.$family = function(){
        return isFinite(this) ? 'number' : 'null';
    }.hide();
    

    .protect() is used by Class, see below.

    This does not mean you can’t do Number.prototype.$family = somethingElse – you can.

    Specifics to Class

    When using implement on a class constructor, notice reference to $hidden and call to wrap():

    var implement = function(key, value, retain){
        if (Class.Mutators.hasOwnProperty(key)){
            value = Class.Mutators[key].call(this, value);
            if (value == null) return this;
        }
    
        if (typeOf(value) == 'function'){
            if (value.$hidden) return this;
            this.prototype[key] = (retain) ? value : wrap(this, key, value);
        } else {
            Object.merge(this.prototype, key, value);
        }
    
        return this;
    };
    

    This means when you pass a function, it will get wrapped automatically – wrapping enables you to have private methods via the .protect() decorator or special ones via .hide()

    It also supports Class Mutators – you should check this but it’s ability to define special keys that can modify the constructor, as opposed to just add to the prototype.

    Once again, you can easily do:

    ClassConstructor.prototype.foo = someFn;
    

    And this will work.

    // but:
    ClassConstructor.prototype.foo = someFn.protect();
    
    // however...
    instanceOfClassconstructor.foo(); // works also.
    

    see this:

    // generic method.
    var foo = function() {
        console.log('hi');
    };
    
    var ClassConstructor = new Class({});
    
    // implement the foo method as private.
    ClassConstructor.implement({
        foo: foo.protect()
    });
    
    var instance = new ClassConstructor();
    
    // try to call it, will throw.
    try {
        instance.foo();
    }
    catch(e) {
        console.warn(e);
    }
    
    // do it directly on the prototype
    ClassConstructor.prototype.foo = foo.protect();
    
    var instance2 = new ClassConstructor();
    instance2.foo(); // works.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Did Facebook just change their iframe size or implement some other breaking change? I
I want to implement a class which its fields could change (add new fields)
Most common ORMs implement persistence by reachability, either as the default object graph change
I am trying to implement some interface changes in my app, based on the
For one of my recent projects, I had to implement field change tracking .
I am trying to implement a function to change state of the menu, but
I am trying to implement a custom membership provider and want to change the
I'm trying to implement change password functionality in Symfony 2 project. I have entity
I am trying implement Unblock me Puzzle. i want to change image position from
is there a way to implement a text change event to detect text change

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.