Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.65 KB | None | 0 0
  1. INDEX.HTML
  2.  
  3. <!DOCTYPE html>
  4. <html>
  5.     <head>
  6.         <!-- <script src="js/functions.js"></script> -->
  7.         <script src="js/objects.js"></script>
  8.     </head>
  9.     <body></body>
  10. </html>
  11.  
  12. FUNCTIONS.JS
  13.  
  14. function doSomething() {
  15.     var value = null;
  16.     for(var i = 0; i < 3; i++) {
  17.        value = function() {
  18.            console.log(i);
  19.        }
  20.    }
  21.    return value;
  22. }
  23.  
  24. var result = doSomething();
  25. result();
  26.  
  27. function doSomething1() {
  28.    var value = null;
  29.    for(let i = 0; i< 3; i ++) {
  30.        value = function() {
  31.            console.log(i);
  32.        }
  33.    }
  34.    return value;
  35. }
  36.  
  37. var result1 = doSomething1();
  38. result1();
  39.  
  40. console.log(result1.prototype);
  41. console.log(result.prototype);
  42.  
  43. function sum(a, b) {
  44.    return a + b;
  45. }
  46.  
  47. function sum1a(a, b=0) {
  48.    return a + b;
  49. }
  50.  
  51. function sum1b(a=0, b=0) {
  52.    return a + b;
  53. }
  54.  
  55. function sum2(a, b) {
  56.    if(typeof a == 'undefined') a = 0;
  57.    if(typeof b == 'undefined') b = 0;
  58.    return a + b;
  59. }
  60.  
  61. function sum3(a, b) {
  62.    return (a || 0) + (b || 0);
  63. }
  64.  
  65. console.log('Suma cu doi parametri', sum(5,4));
  66. console.log('Suma cu un parametru', sum1a(4));
  67. console.log('Suma cu zero parametri', sum1b());
  68. console.log('Suma2', sum2());
  69. console.log('Suma3', sum3());
  70.  
  71. OBJECTS.JS
  72.  
  73. var person = {
  74.    name: 'Gigel',
  75.    surname: 'Popel'
  76. }; //object literals
  77. //var person1 =  new Object;
  78. console.log(person);
  79. //console.log(person1);
  80.  
  81. var student = Object.create(person);
  82. console.log(student);
  83. student.grupa = 1085;
  84. console.log(student.name);
  85.  
  86. var employee = Object.create(student);
  87. employee.salary = 5000;
  88. console.log(employee['salary']);
  89. console.log(employee);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement