implement change prototype, so why not just directory change it with ‘some class’.prototype…, It seems very useless or palaver
implement change prototype, so why not just directory change it with ‘some class’.prototype…, It
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
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:
This means you can do
This allows you to have non-wrapped methods via
.hide()to add properties that are not wrapped:.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
implementon a class constructor, notice reference to$hiddenand call towrap():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:
And this will work.
see this: