Created
March 15, 2015 19:41
-
-
Save jamc92/619ecbd7ac6156fd01fd to your computer and use it in GitHub Desktop.
JS - Functions
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
<script type="text/javascript"> | |
//Creating my object function | |
function myObject() { | |
//Setting myObject as parent of info while it gets a string | |
this.info = "My object info"; | |
//Setting another child of myObject, showInfo that prints this.info value | |
this.showInfo = function() { | |
alert(this.info); | |
} | |
//Setting a function that gets a parameter value | |
this.parameterInfo = function (newInfo) { | |
//Assign the param value to the child info and printing it | |
this.info = newInfo; | |
alert(this.info); | |
} | |
} | |
//Instancing new objects of my main function | |
var anonFunction = new myObject(); | |
var paramFunction = new myObject(); | |
</script> | |
</head> | |
<body> | |
<!--Showing with alerts what values comes from--> | |
<button onclick="anonFunction.showInfo()">anonFunction</button> | |
<button onclick="paramFunction.parameterInfo('Parameter Function')">parameterFunction</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment