Skip to content

Instantly share code, notes, and snippets.

@nebiros
Created February 9, 2015 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nebiros/16bd12e780e29a376e30 to your computer and use it in GitHub Desktop.
Save nebiros/16bd12e780e29a376e30 to your computer and use it in GitHub Desktop.
function Blah() { // función constructora, constructor o clase
this.value = 42; // atributo
}
Blah.prototype = { // atributo 'prototype'
constructor: Blah, // atributo 'constructor'
method: function() { // método
return "hiya!";
}
};
// una instancia de Blah
var blah = new Blah();
// el valor de nuestro atributo 'value'
console.log(blah.value); // 42
// lo que retorna nuestro método 'method'
console.log(blah.method()); // hiya!
// uno de los métodos que heredamos de 'Object'
console.log(blah.toString()); // [object Object]
// el tipo de 'method'
console.log(typeof blah.method); // function
// constructor
console.log(blah.constructor === Blah); // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment