Skip to content

Instantly share code, notes, and snippets.

@meetzaveri
Created August 24, 2018 11:56
Show Gist options
  • Save meetzaveri/58e924e4be53118d0c02c78f9a8c24cd to your computer and use it in GitHub Desktop.
Save meetzaveri/58e924e4be53118d0c02c78f9a8c24cd to your computer and use it in GitHub Desktop.

JS caveats

  • Delete Array.prototype.push and push method will not work for all arrays.
  • As you can call function before and define it after in the program it'll work, but defining prototype methods after and calling it before will throw 'not a function' error
function foo(a){
 this.a =  a;
}

// define after call before - function (success)
console.log(baz());
function baz () {
  return 'baz returned'
}

foo.obno = function () {
  console.log('obno');
}
console.log(foo.prototype.ojo(),foo.prototype);

// define after call before - prototype method (error)
var bar = new foo(7);
console.log('bar',bar);
bar.ojo();
foo.prototype.ojo = function (){
  console.log('ojo',this.a);
  return 'a ojo returned';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment