Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. // SCOPE / HOISTING
  2.  
  3.  
  4. function something() {
  5.  
  6.  
  7. for (var i = 0; i< 10; i++) {
  8.  
  9. //console.log('before' + text);
  10.  
  11. var text = 'Hello ' + i;
  12. //text = 'x';
  13. console.log(text);
  14.  
  15. }
  16.  
  17. //console.log('Outside: ' + text);
  18.  
  19. }
  20.  
  21.  
  22.  
  23. // CLOSURES
  24.  
  25. function test () {
  26. let counter = 0;
  27.  
  28. return function inc() {
  29.  
  30. counter++;
  31. console.log(counter);
  32. }
  33. }
  34.  
  35. // this
  36.  
  37. let obj = {
  38. x: 'hello',
  39. m: function () {
  40. console.log(this.x);
  41. }
  42. }
  43.  
  44.  
  45.  
  46. let obj2 = {x: 'yo'};
  47.  
  48.  
  49. function Constr() {
  50. this.x = 'hello';
  51. this.m = () => {
  52. console.log(this.x);
  53. };
  54. }
  55.  
  56. let obj3 = new Constr();
  57.  
  58.  
  59.  
  60. function context() {
  61. obj.m();
  62. // let f = obj.m;
  63. // let f = obj.m.bind(obj);
  64. // f();
  65. // obj.m.call(obj2);
  66. // setTimeout(obj.m, 700);
  67. }
  68.  
  69.  
  70. // PROTOTYPE
  71.  
  72. function Car() {
  73. this.wheels = 4;
  74. }
  75.  
  76. function proto() {
  77. console.log(Car.prototype.constructor === Car);
  78. }
  79.  
  80. function Person(name) {
  81. this.name = name;
  82. }
  83.  
  84. Person.prototype.sayMyName = function () {
  85. console.log(this.name);
  86. }
  87.  
  88. function BadPerson(name) {
  89. this.name = name;
  90.  
  91. }
  92.  
  93. BadPerson.prototype = Object.create(Person.prototype);
  94.  
  95. BadPerson.prototype.steal = function () {console.log('stole something')};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement