Skip to content

Instantly share code, notes, and snippets.

@jamc92
Created March 15, 2015 19:42
Show Gist options
  • Save jamc92/b3067e215cc8bc696c34 to your computer and use it in GitHub Desktop.
Save jamc92/b3067e215cc8bc696c34 to your computer and use it in GitHub Desktop.
JS - Arguments to functions
<!DOCTYPE html>
<html>
<head>
<title>Arguments to construct functions</title>
</head>
<body>
<script type="text/javascript">
//My object function with parameters
function Book(title, edition, year) {
//Assigning parameters values to an property object
this.title = title;
this.edition = edition;
this.year = year;
//Assigning a string concatenating properties objects to another property object
this.info = ("Hi, this book is about " + this.title + " its edition is " + this.edition + " and it was printed on " + this.year );
//Declaring an anon functon to print info child of parent book
this.showInfo = function() {
alert(this.info);
}
}
//Instacing bew objects from Book, to book1 and book2, passing arguments to the call
var book1 = new Book("FullStack JS", "2nd", "2014");
var book2 = new Book("ECMAScript 6", "6th", "2015");
//Adding a function to an object already instaced using prototype and anon function
Book.prototype.advantages = function() {
//Ptinting out a property object with a extra string
alert(this.title + " Frontend and Backend");
}
</script>
</body>
<!--Calling two instaced var from parent Book-->
<button onclick="book1.showInfo()">First book</button>
<button onclick="book2.showInfo()">First book</button>
<!--Calling a new property object configured by prototype-->
<button onclick="book1.advantages()">First book</button>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment