Skip to content

Instantly share code, notes, and snippets.

@conifertw
conifertw / new_gist_file.js
Created October 21, 2013 16:00
Object-Oriented Javascript p.208
if (typeof window.addEventListener === 'function') { // feature is supported, let's use it } else { // hmm, this feature is not supported, will have to think of another way }
@conifertw
conifertw / javascript_resources.md
Created October 21, 2013 15:52 — forked from jookyboi/javascript_resources.md
Here are a set of libraries, plugins and guides which may be useful to your Javascript coding.

Libraries

  • jQuery - The de-facto library for the modern age. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
  • Backbone - Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • AngularJS - Conventions based MVC framework for HTML5 apps.
  • Underscore - Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
  • lawnchair - Key/value store adapter for indexdb, localStorage
@conifertw
conifertw / gist:5931418
Created July 5, 2013 03:09
Javascript by Example 2nd Example 8.9
<html>
<head><title>The with Keyword</title>
<script type="text/javascript">
function book(title, author, publisher) {
this.title = title;
this.author = author;
this.publisher = publisher;
this.show = show;
}
function show() {
@conifertw
conifertw / gist:5931318
Created July 5, 2013 02:41
Javascript by Example 2nd Example 8.9
<html>
<head><title>The with Keyword</title>
<script type="text/javascript">
function book(title, author, publisher) {
this.title = title;
this.author = author;
this.publisher = publisher;
this.show = show;
}
function show() {
@conifertw
conifertw / gist:5931226
Created July 5, 2013 02:05
Javascript by Example 2nd Example 8.7
<html>
<head><title>Working with literal objects</title>
<script type="text/javascript">
var soldier = {
name: undefined,
rank: "captain",
picture: "keeweeboy.jpg",
fallIn: function() {
alert("At attention, arms at the side, head and eyes forward.");
},
@conifertw
conifertw / gist:5928992
Created July 4, 2013 16:36
Javascript by Example 2nd Example 8.6
<html>
<head><title>functions</title>
<script type="text/javascript">
function Distance(r, t) {
this.rate = r;
this.time = t;
this.calculate = function() { return r * t; }
}
</script>
</head>
@conifertw
conifertw / gist:5928833
Last active December 19, 2015 08:49
Javascript by Example 2nd Example 8.5
<html>
<head><title>User-defined objects</title>
<script type="text/javascript">
function Book(title, author, publisher) {
this.pagenumber = 0;
this.title = title;
this.author = author;
this.publisher = publisher;
this.uppage = pageForward;
this.backpage = pageBackward;
@conifertw
conifertw / gist:5928788
Created July 4, 2013 15:55
Javascript by Example 2nd Example 8.4
<script type="text/javascript">
function Book() {
this.title = "The White Tiger";
this.author = "Aravind Adiga";
}
var bookObj = new Book;
alert(bookObj.title + " by " + bookObj.author);
</script>
@conifertw
conifertw / gist:5928609
Created July 4, 2013 15:25
Javascript by Example 2nd Example 8.3
<html>
<head><title>user-defined objects</title>
<script type="text/javascript">
var toy = new Object();
toy.name = "Lego";
toy.color = "red";
toy.shape = "rectangle";
toy.display = printObject;
function printObject() {
@conifertw
conifertw / gist:5928093
Created July 4, 2013 14:06
Javascript by Example 2nd Example 7.13
<html>
<head><title>Cathc me if you Can!</title></head>
<body>
<script type="text/javascript">
var age = eval(prompt("Enter your age:", ""));
try {
if(age > 120 || age < 0) {
throw "Error1";
} else if(age == "") {
throw "Error2";