Guest User

Untitled

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