Popular Posts
javax.net.ssl.SSLHandshakeException: Connection closed by peer in Android 5.0 Lollipop Recently, there is a error occurs when access website via ssl connection like below although it worked fine several days ago. // Enable SSL... Enable SSL connection for Jsoup import org.jsoup.Connection; import org.jsoup.Jsoup; import javax.net.ssl.*; import java.io.IOException; import java.security.KeyManagement... Build an OpenVPN server on android device Preparation An android device, in this case, Sony xperia Z is used Root permission required Linux Deploy for deploy i...
Stats
Javascript lambda: No binding of this
  1. <form>
  2.     <p>
  3.         <button id="f1">Invoke with function</button>
  4.     </p>
  5.     <p>
  6.         <button id="f2">Invoke with lambda</button
  7.     </p>
  8.     <div id="output"></div>
  9. </form>
  10. <script>
  11.     'use strict';
  12.     (function () {
  13.         let f1 = document.querySelector('#f1'),
  14.             f2 = document.querySelector('#f2'),
  15.             output = document.querySelector('#output');
  16.  
  17.         function appendResult(message) {
  18.             let log = document.createElement('pre');
  19.             log.appendChild(document.createTextNode(message));
  20.             output.appendChild(log);
  21.         }
  22.  
  23.         // define with function, reference 'this' to button element
  24.         f1.onclick = function () {
  25.             appendResult('Button [Invoke with function] clicked!');
  26.             appendResult('This is: ' + JSON.stringify(this) + ' [' + this.constructor.name + ']');
  27.             console.log(this);
  28.             return false;
  29.         };
  30.  
  31.         // define with lambda, reference 'this' to {name: 'Bruce'} object
  32.         f2.onclick = () => {
  33.             appendResult('Button [Invoke with lambda] clicked!');
  34.             appendResult('This is: ' + JSON.stringify(this) + ' [' + this.constructor.name + ']');
  35.             console.log(this);
  36.             return false;
  37.         };
  38.  
  39.     }).call({name: 'Bruce'})
  40. </script>
Result:

Reference: No binding of this