Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>JS Bin</title>
- </head>
- <body>
- <script id="jsbin-javascript">
- //using object syntax
- 'use strict';
- var person1 = {
- name: 'Gaurav',
- age: '26',
- gender: 'male',
- greetings: function greetings() {
- console.log('Hi ' + this.name);
- },
- bio: function bio() {
- console.log(this.name + ' is ' + this.age + ' years old');
- }
- };
- person1.greetings();
- person1.bio();
- // using constructor
- function Person(name, age, gender) {
- this.name = name;
- this.age = age;
- this.gender = gender;
- this.greetings = function () {
- console.log("hello from object 2");
- };
- this.bio = function () {
- console.log('Hi ' + this.name + ' is ' + this.age + ' years old');
- };
- }
- var person2 = new Person("Tejas", '5', 'M');
- person2.greetings();
- person2.bio();
- //using Object constructor
- var person1 = new Object({
- name: 'Prashant',
- age: '26',
- gender: 'male',
- greetings: function greetings() {
- console.log('Hi ' + this.name);
- },
- bio: function bio() {
- console.log(this.name + ' is ' + this.age + ' years old');
- }
- });
- var person2 = Object.create(person1);
- person2.greetings();
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">//using object syntax
- var person1={
- name:'Gaurav',
- age:'26',
- gender:'male',
- greetings:function(){
- console.log('Hi '+this.name);
- },
- bio:function(){
- console.log(this.name+' is '+this.age+' years old');
- }
- }
- person1.greetings();
- person1.bio();
- // using constructor
- function Person(name,age,gender){
- this.name=name;
- this.age=age;
- this.gender=gender;
- this.greetings =function(){
- console.log("hello from object 2");
- };
- this.bio=function(){
- console.log('Hi '+this.name +' is '+ this.age+' years old');
- }
- }
- var person2= new Person("Tejas",'5','M');
- person2.greetings();
- person2.bio();
- //using Object constructor
- var person1=new Object({
- name:'Prashant',
- age:'26',
- gender:'male',
- greetings:function(){
- console.log('Hi '+this.name);
- },
- bio:function(){
- console.log(this.name+' is '+this.age+' years old');
- }
- });
- var person2= Object.create(person1);
- person2.greetings();</script></body>
- </html>
Add Comment
Please, Sign In to add comment