How to get a function name as a string?

my_function.__name__ Using __name__ is the preferred method as it applies uniformly. Unlike func_name, it works on built-in functions as well: >>> import time >>> time.time.func_name Traceback (most recent call last): File “<stdin>”, line 1, in ? AttributeError: ‘builtin_function_or_method’ object has no attribute ‘func_name’ >>> time.time.__name__ ‘time’ Also the double underscores indicate to the reader this … Read more

What is the scope of variables in JavaScript?

TLDR JavaScript has lexical (also called static) scoping and closures. This means you can tell the scope of an identifier by looking at the source code. The four scopes are: Global – visible by everything Function – visible within a function (and its sub-functions and blocks) Block – visible within a block (and its sub-blocks) … Read more

Set a default parameter value for a JavaScript function

From ES6/ES2015, default parameters are in the language specification. function read_file(file, delete_after = false) { // Code } just works. Reference: Default Parameters – MDN Default function parameters allow formal parameters to be initialized with default values if no value or undefined is passed. In ES6, you can simulate default named parameters via destructuring: // … Read more

What is the difference between call and apply?

The difference is that apply lets you invoke the function with arguments as an array; call requires the parameters be listed explicitly. A useful mnemonic is “A for array and C for comma.” See MDN’s documentation on apply and call. Pseudo syntax: theFunction.apply(valueForThis, arrayOfArgs) theFunction.call(valueForThis, arg1, arg2, …) There is also, as of ES6, the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)