Last active
March 11, 2024 13:50
-
-
Save gufranco-zz/5876078 to your computer and use it in GitHub Desktop.
JavaScript object prototype
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
;$(function() { | |
var fooBar = new FooBar(); // constructor | |
fooBar.foo(); // foo | |
fooBar.bar(); // bar | |
}); |
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
/** | |
* FooBar object | |
* | |
* @author Gustavo Franco | |
* @since 2013-06-27 | |
*/ | |
;var FooBar = (function($, window, document, undefined) { | |
'use strict'; | |
/** | |
* Constructor method | |
* | |
* @author Gustavo Franco | |
* @since 2013-06-27 | |
*/ | |
function FooBar() { | |
try { | |
console.log('constructor'); | |
} catch (exception) { | |
console.error(exception.message); | |
} | |
} | |
/** | |
* Foo method | |
* | |
* @author Gustavo Franco | |
* @since 2013-06-27 | |
*/ | |
FooBar.prototype.foo = function() { | |
try { | |
console.log('foo'); | |
} catch (exception) { | |
console.error(exception.message); | |
} | |
}; | |
/** | |
* Bar method | |
* | |
* @author Gustavo Franco | |
* @since 2013-06-27 | |
*/ | |
FooBar.prototype.bar = function() { | |
try { | |
console.log('bar'); | |
} catch (exception) { | |
console.error(exception.message); | |
} | |
}; | |
return FooBar; | |
})(jQuery, window, document); |
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>Object prototype example</title> | |
</head> | |
<body> | |
<p>Open the console ;)</p> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script> | |
<script src="FooBar.js"></script> | |
<script src="bootstrap.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment