borsha06

Practice

Apr 21st, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Practice  */
  2. /* Example of Primitive  */
  3.  
  4. <script>
  5. var person ="borsha";
  6. var another = person;
  7. person = "rofi";
  8.  
  9. console.log(person);
  10. console.log(another);
  11. /* end */
  12.  
  13. /* Example of Refernce */
  14.  
  15. var person ={"name": "Borsha","Age": 24};
  16.  
  17. var another = person;
  18. person.name="Rofi";
  19.  
  20. document.write(person.name);
  21. document.write(another.name);
  22. /* End */
  23.  
  24. /*  Object Example with object literals  */
  25. var person = {"name":"Borsha", "Age": 24,
  26.  
  27. showName: function(){
  28.    
  29.    document.write(person.name);
  30. }
  31.    
  32.    
  33. };
  34.  
  35. person.showName();
  36.  
  37. /* objects example with constructor */
  38.  
  39. var Person = new Object();
  40.  
  41. Person.name = "Borsha";
  42. Person.age = 24
  43.  
  44.  
  45. Person.showName = function(){
  46.    
  47.    document.write(Person.name);
  48. };
  49.    
  50.  
  51. Person.showName();
  52. /* end */
  53. /* Constructor Pattern */
  54.  
  55. function Person(gender,name,age,color,height){
  56.    
  57.     this.gender = gender;
  58.     this.name = name;
  59.     this.age = age;
  60.     this.color = color;
  61.     this.height = height;
  62.    
  63.     this.showName = function(){
  64.         document.write(this.name + "is a "+this.gender);
  65.     }
  66. }
  67.  
  68. var Borsha = new Person("female","Borsha",24,"brown",5.3);
  69. var Rofi = new Person("male","Rofi",24,"brown",5.8);
  70. console.log(Borsha.gender);
  71. Borsha.showName();
  72. Rofi.showName();
  73.  
  74. /*  End  */
  75.  
  76. /*  Prototype Based  */
  77. function Person (emo)
  78. {
  79.     this.emo = "sad"
  80.  
  81. }
  82.  
  83.    
  84.     Person.prototype.gender = "female";
  85.     Person.prototype.name = "Borsha";
  86.     Person.prototype.age = 24;
  87.     Person.prototype.color = "brown";
  88.     Person.prototype.height = 5.3;
  89.    
  90.     Person.prototype.showName = function(){
  91.         document.write(this.name + " is a "+this.gender);
  92.     }
  93.  
  94.  
  95. var Borsha = new Person();
  96. var Rofi = new Person();
  97. console.log(Borsha.gender);
  98. console.log(Borsha.emo);
  99. Borsha.showName();
  100.  
  101. /* End  */
  102.  
  103. </script>
Advertisement
Add Comment
Please, Sign In to add comment