problema alcance

In this example below you will see how to do a problema alcance with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by 0utKast, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright 0utKast ©
  • HTML
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>problema alcance</title>
  
  
  
  
  
</head>

<body>

  <body>
<p>Problema alcance.</p>
<p id="demo"></p>
<script>
function retrasarSaludo(nombre) {
    this.nombre = nombre;
    this.hola = function () {
        setTimeout(function () {
            alert('Hola ' + this.nombre);
        }, 0);
    };
}
var saludo = new retrasarSaludo('Pedro');
saludo.hola(); // alerta 'Hola undefined'
</script>
</body>
  
  

</body>

</html>

Comments