I want to be able to run a function that is passed by name from a data attribute on the HTML side. I've tried the following below.  HTML:  &lt;div class="generic-select" data-help-on-shown="genericFunction" &gt;           &lt;/div&gt;   Javascript:  function genericFunction() {     console.log("generic function called"); }   Other Javascript (separate file):  //stepEl is correct divider from above var genFunction = typeof (stepEl.data("helpOnShown")) === "undefined"                     ? null                     : stepEl.data("helpOnShown");  //this prints "genericFunction" as expected console.log("genFunction = " + genFunction);  if (genFunction) {     genFunction(); //gives error! }   However, this gives me an error. Is there a way to call a function by a string name?
5575
I have the name of a function in JavaScript as a string. How do I convert that into a function pointer so I can call it later?  Depending on the circumstances, I may need to pass various arguments into the method too.  Some of the functions may take the form of namespace.namespace.function(args[...]).
16404
I have the following HTML &lt;select&gt; element:  &lt;select id="leaveCode" name="leaveCode"&gt;   &lt;option value="10"&gt;Annual Leave&lt;/option&gt;   &lt;option value="11"&gt;Medical Leave&lt;/option&gt;   &lt;option value="14"&gt;Long Service&lt;/option&gt;   &lt;option value="17"&gt;Leave Without Pay&lt;/option&gt; &lt;/select&gt;   Using a JavaScript function with the leaveCode number as a parameter, how do I select the appropriate option in the list?
92031
Whats this syntax useful for :       function(String... args)   Is this same as writing       function(String[] args)    with difference only while invoking this method or is there any other feature involved with it ?
29988
I have a problem with an object I have created that looks something like this:  var myObject = {      AddChildRowEvents: function(row, p2) {         if(document.attachEvent) {             row.attachEvent('onclick', function(){this.DoSomething();});         } else {             row.addEventListener('click', function(){this.DoSomething();}, false);         }     },      DoSomething: function() {         this.SomethingElse(); //&lt;-- Error here, object 'this' does not support this method.     } }   The problem is that when I am inside the 'DoSomething' function, 'this' does not refer to 'myObject' what am I doing wrong?
104708
I'm working on a web page where I'm making an AJAX call that returns a chunk of HTML like:   &lt;div&gt;   &lt;!-- some html --&gt;   &lt;script type="text/javascript"&gt;     /** some javascript */   &lt;/script&gt; &lt;/div&gt;   I'm inserting the whole thing into the DOM, but the JavaScript isn't being run.  Is there a way to run it?    Some details: I can't control what's in the script block (so I can't change it to a function that could be called), I just need the whole block to be executed.  I can't call eval on the response because the JavaScript is within a larger block of HTML.  I could do some kind of regex to separate out the JavaScript and then call eval on it, but that's pretty yucky.  Anyone know a better way?
92503
I have a lightning component that is using ui:inputSelect.   The component code:              &lt;div class="slds-form-element__control"&gt;                 &lt;ui:inputSelect class="slds-select" aura:id="quals" change="{!c.getPreCodes}"&gt;                     &lt;aura:iteration items="{!v.questions}" var="q"&gt;                          &lt;ui:inputSelectOption aura:id="question" text="{!q.Id}" label="{!q.Question_Text__c}"/&gt;                     &lt;/aura:iteration&gt;                 &lt;/ui:inputSelect&gt;             &lt;/div&gt;   The controller:      getPreCodes : function(cmp, event, helper){         var selected = cmp.find("quals").get("v.value");          var action = cmp.get("c.getPreCodes");         action.setParams({             "qualID" : selected         });         action.setCallback(this, function(response){             var state = response.getState();             if (state === "SUCCESS") {                  console.log('precodes: ', response.getReturnValue());              }         });          $A.enqueueAction(action);     }   The basic logic is that the uiSelect is dynamically populated on init (this works fine). When a user makes a selection the "change" parameter function is fired to retrieve a list from the database and pass it to another component.   However, the change function {!c.getPreCodes} seems to be called recursively causing a      "Something has gone wrong. AuraClientService.postProcess: error in   processing [RangeError: Maximum call stack size exceeded] . Please try   again."   error. If I comment out the enqueueAction the function only runs once (nothing is called recursively) so I suspect it has something to do with the controller call.
103418
HTML  more code here...  &lt;script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="https://example.com/sites/all/modules/ac_modules/ac_exercise/ac_exercise.js?nkuo2r"&gt;&lt;/script&gt;   more code here...  &lt;div class="form-item form-type-textfield form-item-time-start"&gt;   &lt;label for="edit-time-start"&gt;Time Start &lt;/label&gt;  &lt;input type="text" id="edit-time-start" name="time_start" value="11:28:12" size="4" maxlength="8" class="form-text" /&gt; &lt;/div&gt;   more code here...  Javascript - ac_exercise.js  $(document).ready(function(){    $("#edit-time-start").on("change paste keyup", function() {      alert($(this).val());    }); });   In Chrome's console I get the following error: Uncaught TypeError: undefined is not a function - ac_exercise.js?nkuo2r:1 which is this line of code:  $(document).ready(function(){
104469
Is there a way to pass a call back function in a Java method?  The behavior I'm trying to mimic is a .Net Delegate being passed to a function.  I've seen people suggesting creating a separate object but that seems overkill, however I am aware that sometimes overkill is the only way to do things.
93193
Trying to populate an lightning attribute if a single record exists and if multiple records exists would like to provide the user a select list to choose the record then set the attribute.  I cannot seem to get the lightning:select to get its value to be set:  Component  &lt;aura:component description="Account_Selection" controller="MyController"&gt;         &lt;!-- Handle component initialization in a client-side controller --&gt;         &lt;aura:handler name="init" value="{!this}" action="{!c.doInit}"/&gt;          &lt;!-- The list of accounts to display --&gt;         &lt;aura:attribute name="accounts" type="Account[]"/&gt;          &lt;lightning:select aura:id="a_opt" name="a_opt" label="Accounts"  onchange="{!c.onSelectChange}"&gt;             &lt;aura:iteration items="{!v.accounts}" var="account"&gt;                 &lt;option value="{!account.Id}"&gt;{!account.Name}&lt;/option&gt;             &lt;/aura:iteration&gt;         &lt;/lightning:select&gt; &lt;/aura:component&gt;   Controller  ({     doInit : function(component, event, helper) {         //console.log('here');         helper.getAccounts(component);     },      onSelectChange : function(component, event, helper) {         // Print out the selected value         var selected = component.find("a_opt").get("v.value");         console.log('@@@@@@@: ' + selected);     } })   Helper  ({     getAccounts : function(cmp) {          var action = cmp.get("c.getAccounts");          action.setCallback(this, function(response){             var state = response.getState();             if (state === "SUCCESS") {                 cmp.set("v.accounts", response.getReturnValue());                 cmp.set("v.accountId","ANIDTOTESTTHESET");                 var sel = cmp.find('a_opt');                 sel.set("v.value","ANIDTOTESTSETTINGTHEVALUE");             }         });          $A.enqueueAction(action);     } })   Now, the select DOES show the available select options but I cannot for the life of me get the value to be set via the code.   The above component is within a parent component as so:  &lt;c:Account_Selection aura:id="a_selection"/&gt;   The parent component has an attribute  &lt;aura:attribute name="accountId" type="Id"/&gt;   What I would like to happen:   If only one account record returned from the apex controller, set the value of the accountId attribute to the Id of that record If multiple accounts found, set the default value of the select list to a specific value and set the attribute value If user selects a value then set the value of the attribute   I have tried everything I can think of searched but cannot get it to work. The select list has all the options but the first value seems to always be selected regardless of the value I attempt to set.   The outPutText does not have any value despite explicitly setting it from the component..  Any ideas how to make this work?   Update  I think the issue is the "cmp" is not the lightning component it is the apex controller? How do i get a reference back to the component on the callback?
24985
I saw , but I didn't see a JavaScript specific example. Is there a simple string.Empty available in JavaScript, or is it just a case of checking for ""?
117179
I'm trying to pass one method to another in elisp, and then have that method execute it.  Here is an example:  (defun t1 ()   "t1")  (defun t2 ()   "t1")  (defun call-t (t)   ; how do I execute "t"?   (t))  ; How do I pass in method reference? (call-t 't1)
119239
I have a variable, x, and I want to know whether it is pointing to a function or not.  I had hoped I could do something like:  &gt;&gt;&gt; isinstance(x, function)   But that gives me:  Traceback (most recent call last):   File "&lt;stdin&gt;", line 1, in ? NameError: name 'function' is not defined   The reason I picked that is because  &gt;&gt;&gt; type(x) &lt;type 'function'&gt;
51439
How do you do "inline functions" in C#? I don't think I understand the concept. Are they like anonymous methods? Like lambda functions?  Note: The answers almost entirely deal with the ability to , i.e. "a manual or compiler optimization that replaces a function call site with the body of the callee." If you are interested in , see  or .
25453
I have created a 'control' using jQuery and used jQuery.extend to assist in making it as OO as possible.  During the initialisation of my control I wire up various click events like so  jQuery('#available input',              this.controlDiv).bind('click', this, this.availableCategoryClick);   Notice that I am pasing 'this' as the data argument in the bind method. I do this so that I can get at data attached to the control instance rather from the element that fires the click event.   This works perfectly, however i suspect there is a better way  Having used Prototype in the past, I remember a bind syntax that allowed you to control what the value of 'this' was in the event.  What is the jQuery way?
112004
I have a Linq query that I want to call from multiple places:  var myData = from a in db.MyTable              where a.MyValue == "A"              select new  {                             a.Key,                             a.MyValue                           };   How can I create a method, put this code in it, and then call it?  public  ???  GetSomeData() {    // my Linq query }
37922
I'm trying to implement the sorting functionality on a lightning:datatable. Sorting works one way (descending, clicking the column header again and nothing happens). I have followed the documentation and here's my code below:  &lt;aura:attribute name="selectedAccountId" type="Id" access="public" /&gt; &lt;aura:attribute name="accounts" type="Object"/&gt; &lt;aura:attribute name="mycolumns" type="List"/&gt; &lt;aura:handler name="init" value="{! this }" action="{! c.doInit }"/&gt;  &lt;aura:registerEvent name="AccountFilterChange" type="c:AccountFilterChange" /&gt;   &lt;lightning:datatable aura:id="lightningTable"                      data="{! v.accounts }"                      columns="{! v.mycolumns }"                      keyField="Id"                      onrowaction="{! c.handleRowAction }"                      onsort="{!c.updateColumnSorting}"                      hideCheckboxColumn="true" /&gt;   Controller:  doInit: function(component, event, helper) {    helper.callServer(component, "c.getAccounts", function(response) {        component.set("v.accounts", response);        })     component.set('v.mycolumns', [         {type: "button", typeAttributes: {             label: '',             iconName: 'utility:add',             name: 'selectRecord',             title: 'selectRecord',             disabled: false,             value: 'edit',             variant: {fieldName: 'variantValue'},         }},         {label: 'Name', fieldName: 'Name', type: 'text', sortable: true},             ]);         },  handleRowAction: function(component, event, helper) {     var account = event.getParam("row")     var action = event.getParam("action");     if (action.name == "selectRecord") {         var event = component.getEvent("AccountFilterChange");          event.setParams({             accountId: account.Id,         });     }  event.fire();  helper.addRow(component, account); },  updateColumnSorting: function(component, event, helper) {     var fieldName = event.getParam('fieldName');     var sortDirection = event.getParam('sortDirection');     // assign the latest attribute with the sorted column fieldName and sorted direction     component.set("v.sortedBy", fieldName);     component.set("v.sortedDirection", sortDirection);     helper.sortData(component, fieldName, sortDirection);     }   Helper:  sortData: function (component, fieldName, sortDirection) {      var data = component.get("v.accounts");      var reverse = sortDirection !== 'asc';      //sorts the rows based on the column header that's clicked      data.sort(this.sortBy(fieldName, reverse))      component.set("v.accounts", data);      },  sortBy: function (field, reverse, primer) {      var key = primer ? function(x) {return primer(x[field])} : function(x) {return x[field]};      //checks if the two rows should switch places      reverse = !reverse ? 1 : -1;      return function (a, b) {          return a = key(a), b = key(b), reverse * ((a &gt; b) - (b &gt; a));      }  }   How would I make this work so both desc/asc will work when clicking the column header?
1947
What's the best way to call a generic method when the type parameter isn't known at compile time, but instead is obtained dynamically at runtime?  Consider the following sample code - inside the Example() method, what's the most concise way to invoke GenericMethod&lt;T&gt;() using the Type stored in the myType variable?  public class Sample {     public void Example(string typeName)     {         Type myType = FindType(typeName);          // What goes here to call GenericMethod&lt;T&gt;()?         GenericMethod&lt;myType&gt;(); // This doesn't work          // What changes to call StaticMethod&lt;T&gt;()?         Sample.StaticMethod&lt;myType&gt;(); // This also doesn't work     }      public void GenericMethod&lt;T&gt;()     {         // ...     }      public static void StaticMethod&lt;T&gt;()     {         //...     } }