I often need a function fto get the name of a method that points to f. For instance. Let's say we have a function getMethodName(obj, methodFunction)that uses foreachon objto find a property that is a reference to methodFunction:
f
getMethodName(obj, methodFunction)
foreach
obj
methodFunction
obj = { foo : function() { var myName = getMethodName(obj, arguments.callee); // "foo" } }
How to do it in strict mode , where it is arguments.calleedeprecated?
arguments.callee
You cannot do this. And you should not do this in the first place, this is magic, your function should not depend on its caller, etc. Change your design so that it works again.
arguments.callee .caller - , , . , -, , , - .
.caller
: http://whereswalden.com/2010/09/08/new-es5-strict-mode-support-now-with-poison-pills/
, , , , :
obj = { foo : function METHODNAME() { var myName = getMethodName(obj, METHODNAME); // "foo" } }
: , IE , METHODNAME ( ). , , , , , , eval, eval.
METHODNAME
eval
Source: https://habr.com/ru/post/1784400/More articles:Setting the computer volume - javajava overloaded method - java(PHP): Testing models with Zend_Test_PHPUnit_DatabaseTestCase - phpWhy does this example interface tree not work? - javaJava Sound APIs for accessing the system / master volume control in Vista and Win 7 - javaCodeigniter variables from constructor undefined - functionCreating serializable unique compile-time identifiers for arbitrary UDTs - c ++(HibernateSearch) MultiFieldQueryParser for each field - javaBest sequence of methods for the Ruby on Rails model? - ruby | fooobar.comPassing certificate and key as der_bin () to Erlang using ssl - erlangAll Articles