Guest User

Untitled

a guest
May 24th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9. <p>Please check developer console</p>
  10. <script id="jsbin-javascript">
  11. //using object syntax
  12.  
  13. var person1={
  14. name:'Gaurav',
  15. age:'26',
  16. gender:'male',
  17. greetings:function(){
  18. console.log('Hi '+this.name);
  19. },
  20. bio:function(){
  21. console.log(this.name+' is '+this.age+' years old');
  22. }
  23.  
  24. }
  25. person1.greetings();
  26. person1.bio();
  27.  
  28. // using constructor
  29.  
  30. function Person(name,age,gender){
  31. this.name=name;
  32. this.age=age;
  33. this.gender=gender;
  34. this.greetings =function(){
  35. console.log("hello from object 2");
  36. };
  37. this.bio=function(){
  38. console.log('Hi '+this.name +' is '+ this.age+' years old');
  39. }
  40. }
  41. var person2= new Person("Tejas",'5','M');
  42.  
  43. person2.greetings();
  44. person2.bio();
  45.  
  46. //using Object constructor
  47.  
  48. var person1=new Object({
  49. name:'Prashant',
  50. age:'26',
  51. gender:'male',
  52. greetings:function(){
  53. console.log('Hi '+this.name);
  54. },
  55. bio:function(){
  56. console.log(this.name+' is '+this.age+' years old');
  57. }
  58.  
  59. });
  60. var person2= Object.create(person1);
  61. person2.greetings();
  62. </script>
  63.  
  64.  
  65.  
  66. <script id="jsbin-source-javascript" type="text/javascript">//using object syntax
  67.  
  68. var person1={
  69. name:'Gaurav',
  70. age:'26',
  71. gender:'male',
  72. greetings:function(){
  73. console.log('Hi '+this.name);
  74. },
  75. bio:function(){
  76. console.log(this.name+' is '+this.age+' years old');
  77. }
  78.  
  79. }
  80. person1.greetings();
  81. person1.bio();
  82.  
  83. // using constructor
  84.  
  85. function Person(name,age,gender){
  86. this.name=name;
  87. this.age=age;
  88. this.gender=gender;
  89. this.greetings =function(){
  90. console.log("hello from object 2");
  91. };
  92. this.bio=function(){
  93. console.log('Hi '+this.name +' is '+ this.age+' years old');
  94. }
  95. }
  96. var person2= new Person("Tejas",'5','M');
  97.  
  98. person2.greetings();
  99. person2.bio();
  100.  
  101. //using Object constructor
  102.  
  103. var person1=new Object({
  104. name:'Prashant',
  105. age:'26',
  106. gender:'male',
  107. greetings:function(){
  108. console.log('Hi '+this.name);
  109. },
  110. bio:function(){
  111. console.log(this.name+' is '+this.age+' years old');
  112. }
  113.  
  114. });
  115. var person2= Object.create(person1);
  116. person2.greetings();</script></body>
  117. </html>
Add Comment
Please, Sign In to add comment