Skip to content

Commit

Permalink
JS
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornweb committed Sep 29, 2015
1 parent 69b3369 commit eb02324
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
35 changes: 35 additions & 0 deletions JavaScriptexamples/arrayAppend.html
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>
81 changes: 81 additions & 0 deletions JavaScriptexamples/prototypes.html
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>

0 comments on commit eb02324

Please sign in to comment.