-
- $(function () {
- Array.prototype.contains = function (obj) {
- a = this;
- for (var i = 0; i < a.length; i++) {
- if (a[i] === obj) {
- return i;
- }
- }
- return -1;
- };
-
- var console = {};
- console.log = function (msg) {
- $("#result").append(msg.toString() + String.fromCharCode(60) + "br/" + String.fromCharCode(62));
- };
-
- function Car(brand, model) {
- // private member
- var _mileage = 0;
-
- // properties
- this.brand = brand;
- this.model = model;
-
- // methods
- this.run = function (mileage) {
- _mileage = mileage;
- };
- this.getMileage = function () {
- return _mileage;
- };
- }
-
- // class level methods
- Car.prototype.getCarData = function () {
- return this.brand + " " + this.model;
- };
-
- var myCar = new Car("VW", "POLO");
- myCar.run(100);
-
- var carData = myCar.getCarData();
- console.log(carData);
-
- var mileage = myCar.getMileage();
- console.log(mileage);
-
- var cars = [];
- cars.push(new Car("VW", "POLO"));
- cars.push(new Car("VW", "POLO"));
- cars.push(myCar);
-
- console.log(cars.indexOf(myCar));
- console.log(cars.contains(myCar));
- console.log($.inArray(myCar, cars));
-
- cars.forEach(function (item, index) {
- console.log(item.brand + " " + item.model);
- });
-
- for (var i = 0; i < cars.length; i++) {
- console.log(cars[0].brand + " " + cars[0].model);
- }
-
- $.each(cars, function (index, item) {
- console.log(item.brand + " " + item.model);
- });
-
- for (var prop in myCar) {
- if (typeof myCar[prop] == "string") {
- console.log(prop + "=" + myCar[prop]);
- }
- }
- });
-
VW POLO
100
2
2
2
VW POLO
VW POLO
VW POLO
VW POLO
VW POLO
VW POLO
VW POLO
VW POLO
VW POLO
brand=VW
model=POLO