-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
rebornweb
committed
Sep 29, 2015
1 parent
69b3369
commit eb02324
Showing
2 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
<!DOCTYPE html> | ||
|
||
<html> | ||
<head> | ||
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> | ||
|
||
|
||
</head> | ||
|
||
<body> | ||
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></scrip | ||
<div id='result'></div> | ||
|
||
</body> | ||
|
||
<script type='text/javascript'> | ||
//How to deal with a Javascript Array Append | ||
//.Prototype is used to chain the constructor or object | ||
|
||
function arrayAppend() { | ||
var a = [4,5,6]; | ||
var b = [7,8,9]; | ||
Array.prototype.push.apply(a, b); | ||
|
||
uneval(a); // is: [4, 5, 6, 7, 8, 9] | ||
|
||
document.getElementById('result').innerHTML = a; | ||
//alert(a); | ||
} | ||
|
||
arrayAppend(); | ||
|
||
</script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
|
||
<!DOCTYPE html> | ||
|
||
<html> | ||
<head> | ||
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> | ||
|
||
|
||
</head> | ||
|
||
<body> | ||
|
||
<div id='result'></div> | ||
|
||
</body> | ||
|
||
<script type='text/javascript'> | ||
var Person = function() { | ||
this.canTalk = true; | ||
}; | ||
|
||
Person.prototype.greet = function() { | ||
if (this.canTalk) { | ||
console.log('Hi, I am ' + this.name); | ||
} | ||
}; | ||
|
||
var Employee = function(name, title) { | ||
Person.call(this); | ||
this.name = name; | ||
this.title = title; | ||
}; | ||
|
||
Employee.prototype = Object.create(Person.prototype); | ||
//Employee.prototype.constructor = Employee; | ||
|
||
Employee.prototype.greet = function() { | ||
if (this.canTalk) { | ||
console.log('Hi, I am ' + this.name + ', the ' + this.title); | ||
} | ||
}; | ||
|
||
var Customer = function(name) { | ||
Person.call(this); | ||
this.name = name; | ||
}; | ||
|
||
Customer.prototype = Object.create(Person.prototype); | ||
//Customer.prototype.constructor = Customer; You dont need to chain these pieces of code | ||
|
||
var Mime = function(name) { | ||
Person.call(this); | ||
this.name = name; | ||
this.canTalk = true; | ||
}; | ||
|
||
Mime.prototype = Object.create(Person.prototype); | ||
//Mime.prototype.constructor = Mime; | ||
|
||
var bob = new Employee('Bob', 'Builder'); | ||
var joe = new Customer('Joe'); | ||
var rg = new Employee('Red Green', 'Handyman'); | ||
var mike = new Customer('Mike'); | ||
var mime = new Mime('Mime'); | ||
|
||
bob.greet(); | ||
// Hi, I am Bob, the Builder | ||
|
||
joe.greet(); | ||
// Hi, I am Joe | ||
|
||
rg.greet(); | ||
// Hi, I am Red Green, the Handyman | ||
|
||
mike.greet(); | ||
// Hi, I am Mike | ||
|
||
mime.greet(); | ||
|
||
</script> | ||
</html> |