lwc:programming:javascript

This is an old revision of the document!


  • you don't have to use var but if you don't the variable is defined globally (although it still can be deleted.) Seems like bad practice.
  • everything appears to be call-by-value except for arrays and other objects, like functions. So if you wanted to change variable a you could make a an array and send the array.
  • you can read the properties associated with an object with “Object.keys($(this))”
 find all elements ids with class “buttonClass” var elements = document.getElementsByClassName(“buttonClass”);
for (var i = 0, len = elements.length; i < len; i++) {

    console.log(elements[i].id);

}
 callback function when mouse leaves button_8  $( document ).on( “vmouseout”, “#button_8”, function(){
 set style of myPath2  document.getElementById(“myPath2”).setAttribute('style',“animation:fade 500ms infinite; -webkit-animation:fade 500ms infinite;”);
 get caller of function  alert(“caller is ” + arguments.callee.caller.toString());
 find all methods of an object  var methods = []; for (var m in obj) { if (typeof obj[m] == “function”) { methods.push(m); } } alert(methods.join(“,”));
 loop through a set of values  [1,2,3,4].map(function(item) {
      alert(item); }) 

Sockets seem to work (in Firefox at least) with this Java bridge. Python script to work with js sockets Load data using ajax and json. stringify? json.parse? It would be possible to interpret even svg files in the browser using json.

  • when using ajax with Phonegap it might be necessary to say in config.xml that you trust 127.0.0.1.

JSON:

  • to save a JSON file, either print it to the screen or send it to a server as explained here.

Ajax:

singleton objects: do them with a “lazy initializer” i.e. this way:

  • MyApp.getInstance = function(){
  •     if(MyApp.instance == null){
  • MyApp.instance = new MyApp();
  • }
  •     return MyApp.instance;
  • };
  • Then in the window environment create the instance:  myApp = MyApp.getInstance();

wrapping a function:

If you have a function call and you need to send it parameters (such as 

$(document).on("vmousedown", myFunction) you can wrap the function inside an anonymous function i.e.\\
$(document).on("vmousedown", function() {\\
    myFunction(parameter)});

Garbage Collection:

  • to see all the event messages flying around: monitorEvents(window);
  • then to unsee: unmonitorEvents(window);
  • lwc/programming/javascript.1668522934.txt.gz
  • Last modified: 2022/11/15 08:35
  • by John Harrison