1

Topic: [JS] to Mark function by attribute

Greetings to all. Whether it is possible in JavaScript' to mark somehow function, for example with something like attribute that then it was possible to find it a reflection? It would be desirable to have possibility in  to find out certain functions. For example so var obj = {f1: function () {return 1;}, f2: function () {return 2;}, g1: function () {return 3;} h1: ' not a function '} for (var key in obj) {if (obj.hasOwnProperty (key) && typeof (obj [key]) == ' function '//&&??) {console.log (' Special function found: %s', key);}} Thanks.

2

Re: [JS] to Mark function by attribute

Hello, SergASh, you wrote: SAS> Greetings to all. Whether SAS> it is possible in JavaScript' to mark somehow function, for example with something like attribute that then it was possible to find it a reflection? SAS> It would be desirable to have possibility in  to find out certain functions. For example so [js] var obj = {f1: function () {return 1;}, f2: function () {return 2;}, g1: function () {return 3;} h1: ' not a function '} obj.f1.tag = ' foo '; obj [' f1 '].tag == ' foo '//=> true [/js] Function - simply object, and at each object is any field. I do not know, however, whether it is possible to consider it as good practice

3

Re: [JS] to Mark function by attribute

Hello, the Small animal, you wrote: > Function - simply object, and at each object is any field. > I do not know, however, whether it is possible to consider it as good practice Already thought of such variant, but that there is no locality here is bad. That is function in one place is declared, and marked somewhere in other. Such it will be difficult to support.

4

Re: [JS] to Mark function by attribute

Hello, SergASh, you wrote: function tag (t, f) {f.tag = t; return f;} var obj = {f1: tag ("FOO", function () {return 1;}), f2: function () {return 2;}, g1: function () {return 3;} h1: ' not a function '} or to use function name var obj = {f1: function Foo () {return 1;}, f2: function () {return 2;}, g1: function () {return 3;} h1: ' not a function '} for (var key in obj) {if (obj.hasOwnProperty (key) && obj [key].name == "Foo") {console.log (' Special function found: %s', key);}}

5

Re: [JS] to Mark function by attribute

Hello, SergASh, you wrote: whether SAS> It is possible in JavaScript' to mark somehow function, for example with something like attribute that then it was possible to find it a reflection? Similar you want something like javascript decorators, which in a deep draft and while by itself are supported by nobody? Is in , type typescript / babel.