Define and use object : Objects Object Oriented « Language Basics « JavaScript DHTML

JavaScript DHTML
1. Ajax Layer
2. Data Type
3. Date Time
4. Development
5. Document
6. Event
7. Event onMethod
8. Form Control
9. GUI Components
10. HTML
11. Javascript Collections
12. Javascript Objects
13. Language Basics
14. Node Operation
15. Object Oriented
16. Page Components
17. Security
18. Style Layout
19. Table
20. Utilities
21. Window Browser
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
JavaScript DHTML » Language Basics » Objects Object Oriented 
Define and use object


<!-- 
     Example File From "JavaScript and DHTML Cookbook"
     Published by O'Reilly & Associates
     Copyright 2003 Danny Goodman
-->


function coworker(name, age) {
    this.name = name;
    this.age = age;
}

var emp1 = new coworker("Alice"23);
var emp2 = new coworker("Fred"32);

----------

var emp1 = {name:"Alice", age:23};
var emp2 = {name:"Fred", age:32};

----------

function showAll() {
    alert("Employee " this.name + " is " this.age + " years old.");    
}

function coworker(name, age) {
    this.name = name;
    this.age = age;
    this.show = showAll;
}

var emp1 = {name:"Alice", age:23, show:showAll};
var emp2 = {name:"Fred", age:32, show:showAll};

emp1.show();

----------

function coworker(name, age) {
    this.name = name;
    this.age = age || 0;
    this.show = showAll;
}

----------

function verify(obj) {
    alert("Just added " + obj.name + ".");
}
function coworker(name, age) {
    this.name = name;
    this.age = age;
    this.show = showAll;
    verify(this);
}

----------

var employeeDB = new Array();
employeeDB[employeeDB.lengthnew coworker("Alice"23);
employeeDB[employeeDB.lengthnew coworker("Fred"32);
employeeDB[employeeDB.lengthnew coworker("Jean"28);
employeeDB[employeeDB.lengthnew coworker("Steve"24);

----------

var employeeDB = new Array();
employeeDB[employeeDB.length{name:"Alice", age:23, show:showAll};
employeeDB[employeeDB.length{name:"Fred", age:32, show:showAll};
employeeDB[employeeDB.length{name:"Jean", age:28, show:showAll};
employeeDB[employeeDB.length{name:"Steve", age:24, show:showAll};

----------

var employeeDB = [{name:"Alice", age:23, show:showAll},
                  {name:"Fred", age:32, show:showAll},
                  {name:"Jean", age:28, show:showAll},
                  {name:"Steve", age:24, show:showAll}];

----------

function findInAgeGroup(low, high) {
    var result = new Array();
    for (var i = 0; i < employeeDB.length; i++) {
        if (employeeDB[i].age >= low && employeeDB[i].age <= high) {
            result = result.concat(employeeDB[i].name);
        }
    }
    return result;
}


           
       
Related examples in the same category
1. Object utility: create, parse and profile
2. Define Object, use its instance
3.  Creating an Object and Using Object Instance Properties and Methods
4.  Object-Oriented Planetary Data Presentation
5. The Book Object Definition
6. Complete Example of Using the employee, client, and project Objects
7. Source Code for the showBook() Example
8. Using the Book Object Constructor
9. Creating Objects Dynamically
10. Object to array
11. Utility class for JavaScript class definition
w__w_w___.__j___av___a___2_s.co_m_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.