names

Javascript: Dynamic function names [duplicate]

…衆ロ難τιáo~ 提交于 2019-12-17 19:35:19
问题 This question already has answers here : Dynamic function name in javascript? (20 answers) Closed 3 years ago . How to create a function with a dynamic name? Something like: function create_function(name){ new Function(name, 'console.log("hello world")'); } create_function('example'); example(); // --> 'hello world' Also the function should be a Function Object so I can modify the prototype of the object. 回答1: window.example = function () { alert('hello world') } example(); or name = 'example

Get anonymous function name

时间秒杀一切 提交于 2019-12-17 16:49:40
问题 How to get the the variable name from within a function in this example: // it should return A var A = function(){ console.log(this.name); } Is there something like this? 回答1: That function is anonymous; it has no name. You could, however, give it a name: var A = function a() {}; Then its name is accessible via Function.name: var A = function a() {}; A.name > 'a' 回答2: I know this is an old thread, but still in search results. so just for reference: a solution could simply be using the

Why the “mutable default argument fix” syntax is so ugly, asks python newbie

…衆ロ難τιáo~ 提交于 2019-12-17 07:30:09
问题 Now following my series of "python newbie questions" and based on another question. Prerogative Go to http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#other-languages-have-variables and scroll down to "Default Parameter Values". There you can find the following: def bad_append(new_item, a_list=[]): a_list.append(new_item) return a_list def good_append(new_item, a_list=None): if a_list is None: a_list = [] a_list.append(new_item) return a_list There's even an "Important

Concatenating Variable Names in C?

时间秒杀一切 提交于 2019-12-17 02:32:09
问题 Is it possible to concatenate variable names in C? Specifically, I have a struct that contains 6 similar variables in it called class1 , class2 , class3 , etc. I want to run through a for loop to assign each variable a value, but I can't see how to do it without somehow concatenating the variable name with the value of the for loop counter. How else could I do this? 回答1: When you find yourself adding an integer suffix to variable names, think I should have used an array . struct mystruct {

Can lists be created that name themselves based on input object names?

喜你入骨 提交于 2019-12-16 20:54:47
问题 It would be very helpful to me to be able to create an R list object without having to specify the names of each element. For example: a1 <- 1 a2 <- 20 a3 <- 1:20 b <- list(a1,a2,a3, inherit.name=TRUE) > b [[a1]] [1] 1 [[a2]] [1] 20 [[a3]] [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 This would be ideal. Any suggestions? 回答1: Coincidentally, I just wrote this function. It looks a lot like @joran's solution, but it tries not to stomp on already-named arguments. namedList <- function(

Using RegEx for validating First and Last names in Java

喜欢而已 提交于 2019-12-12 12:16:36
问题 I am trying to validate a String which contains the first & last name of a person. The acceptable formats of the names are as follows. Bruce Schneier Schneier, Bruce Schneier, Bruce Wayne O’Malley, John F. John O’Malley-Smith Cher I came up with the following program that will validate the String variable. The validateName function should return true if the name format matches any of the mentioned formats able. Else it should return false . import java.util.regex.*; public class telephone {

Validate Title Case Full Name with Regex

大城市里の小女人 提交于 2019-12-12 12:04:20
问题 To learn Regex, I was solving some problems to train and study. And this is the problem, i know it might not be the best way to do with Regex, and my Regex is a mess, but i liked the challenge. Problem: The names needs to be Title Case; There are exceptions for some lowercase words inside; And some Names, e.g.: McDonald, MacDuff, D'Estoile Names with ' and - are accepted, and sometimes they are o'Brien, O'brien, O'Brien, O' Brien or 'Ehu Kali. No whitespaces on the beggining and end of Name;

How to check if a string can be used as a variable name in PHP?

≯℡__Kan透↙ 提交于 2019-12-12 08:01:40
问题 In PHP one can use variable variables... For example... class obj { } $fieldName = "Surname"; $object = new obj(); $object->Name = "John"; $object->$fieldName = "Doe"; echo "{$object->Name} {$object->Surname}"; // This echoes "John Doe". However, $fieldName string may contain some characters not allowed in variable names. PHP will still create the field with that name (much like the associative array), but I will not be able to access it with $object->...... because it would not parse

oracle read column names from select statement

青春壹個敷衍的年華 提交于 2019-12-12 04:32:46
问题 I wonder how read column names in oracle. Ok, I know that there is table named USER_TAB_COLUMNS which gives info about it, but if I have 2 or 3 level nested query and I don't know column names. Or I just have simple query with join statement and i want to get column names. How to do that? any idey? select * from person a join person_details b where a.person_id = b.person_id thanks 回答1: I would go for: select 'select ' || LISTAGG(column_name , ',') within group (order by column_id) || ' from

Modify sorting algorithm to work with listboxes?

血红的双手。 提交于 2019-12-12 03:53:24
问题 So I'm trying to figure out to modify this integer sorting algorithm to work with data elements (file names) alphabetically in a listbox but have no idea how? I understand how the sorting algorithm below works and can implement it using an integer array. However, for listBoxes I can't seem to find any relevant examples on the net. public partial class MainWindow : Window { Random rand = new Random(); int numOfIntegers = 1000; int[] array; public MainWindow() { InitializeComponent(); array =