Skip to content

Instantly share code, notes, and snippets.

@jamc92
Created March 15, 2015 19:41
Show Gist options
  • Save jamc92/619ecbd7ac6156fd01fd to your computer and use it in GitHub Desktop.
Save jamc92/619ecbd7ac6156fd01fd to your computer and use it in GitHub Desktop.
JS - Functions
<!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