Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Practice */
- /* Example of Primitive */
- <script>
- var person ="borsha";
- var another = person;
- person = "rofi";
- console.log(person);
- console.log(another);
- /* end */
- /* Example of Refernce */
- var person ={"name": "Borsha","Age": 24};
- var another = person;
- person.name="Rofi";
- document.write(person.name);
- document.write(another.name);
- /* End */
- /* Object Example with object literals */
- var person = {"name":"Borsha", "Age": 24,
- showName: function(){
- document.write(person.name);
- }
- };
- person.showName();
- /* objects example with constructor */
- var Person = new Object();
- Person.name = "Borsha";
- Person.age = 24
- Person.showName = function(){
- document.write(Person.name);
- };
- Person.showName();
- /* end */
- /* Constructor Pattern */
- function Person(gender,name,age,color,height){
- this.gender = gender;
- this.name = name;
- this.age = age;
- this.color = color;
- this.height = height;
- this.showName = function(){
- document.write(this.name + "is a "+this.gender);
- }
- }
- var Borsha = new Person("female","Borsha",24,"brown",5.3);
- var Rofi = new Person("male","Rofi",24,"brown",5.8);
- console.log(Borsha.gender);
- Borsha.showName();
- Rofi.showName();
- /* End */
- /* Prototype Based */
- function Person (emo)
- {
- this.emo = "sad"
- }
- Person.prototype.gender = "female";
- Person.prototype.name = "Borsha";
- Person.prototype.age = 24;
- Person.prototype.color = "brown";
- Person.prototype.height = 5.3;
- Person.prototype.showName = function(){
- document.write(this.name + " is a "+this.gender);
- }
- var Borsha = new Person();
- var Rofi = new Person();
- console.log(Borsha.gender);
- console.log(Borsha.emo);
- Borsha.showName();
- /* End */
- </script>
Advertisement
Add Comment
Please, Sign In to add comment