Sometimes we are just lazy. Especially when it comes to writing code. And although the parentheses in the function call do not lead to redundancy, sometimes they can still bore, especially when the javascript method does not need arguments passed to it. Sometimes it just bothers you.+myFunction;window.parseFloat(myFunction.valueOf());Function.prototype.valueOf=function(){this.call(this); return 0;};Function.prototype.fix=function(s){var t=this; return function(){ return t.apply(s,arguments); }; };var Foo= function (){
this .myMethod= this .myMethod.fix( this );
};
var Foo= function (){
for ( var i in this )
if ( typeof ( this [i])== "function" )
this [i]= this [i].fix( this );
};* This source code was highlighted with Source Code Highlighter .
- var StandardClass = function () {};
- StandardClass.prototype.initMethods = function () {
- for ( var i in this )
- if ( typeof ( this [i]) == ” function ” && this [i] .dontWrap! == true )
- this [i] = this [i] .fix ( this );
- };
- StandardClass.prototype.initMethods.dontWrap = true ;
- Function.prototype.fix = function (s) {
- var t = this ;
- return function () {
- return t.apply (s, arguments);
- };
- };
- Function.prototype.valueOf = function () {
- this .call ( this );
- return 0;
- };
- var Foo = function (name) {
- this .initMethods ();
- this .name = name;
- };
- Foo.prototype = new StandardClass;
- Foo.prototype.showName = function () {
- alert ( this .name);
- };
- Foo.prototype.showNameUpperCase = function () {
- alert ( this .name.toUpperCase ());
- };
- var myFoo = new Foo (“Hello World”);
- + myFoo.showName;
- + myFoo.showNameUpperCase;
Source: https://habr.com/ru/post/90432/
All Articles