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
tips.push({ | |
author: 'your_twitter_handle', | |
message: 'Your Tip Message', | |
WrongWay: [ | |
'<div>', | |
' Code Example', | |
'</div>' | |
], | |
RightWay: [ | |
'<div>', |
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
javascript:(function() { | |
/* Replace login and apiKey, get your's from http://bit.ly/a/your_api_key */ | |
var login="xxxxxxxxx", | |
apiKey="R_xxxxxxxx", | |
otherlib=false; | |
if (typeof jQuery=='undefined' && typeof $=='function') { | |
otherlib=true; | |
} | |
function getScript(url,success){ | |
var script=document.createElement('script'); |
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
// get | |
object.name | |
object[expression] | |
// set | |
object.name = value; | |
object[expression] = value; | |
// delete | |
delete object.name |
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
var my_object = {foo: bar}; // object literals are a good part of JavaScript | |
// the above is equallant to the following code in ES5 | |
// Notice that a lot of internals are exposed | |
var my_object = Object.defineProperties( | |
Object.create(Object.prototype), { | |
foo: { | |
value: bar, | |
writable: true, | |
enumerable: true, |
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
// You can override and the getters and setters | |
Object.defineProperty(my_object, 'inch',{ | |
get : function() { return this.mm / 25.4; }, | |
set : function(value) { this.mm = value * 25.4; }, | |
enumerable: true | |
}); |
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
Car car = new Car(); // Redundancy |
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
// objects have a prototype attribute | |
Object.create(object, properties) | |
Object.getPrototypeOf(object) // you probably should not use this |
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
// The following will fail if word ==== 'constructor' ... | |
function bump_count(word) { | |
if(word_count[word]){ | |
word_count[word] += 1; | |
}else{ | |
word_count[word] = 1; | |
} | |
} |
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
// The following code will fix the problem | |
function bump_count(word) { | |
if(typeof word_count[word] === 'number'){ | |
word_count[word] += 1; | |
}else{ | |
word_count[word] = 1; | |
} | |
} |
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
// An easy fix would be: | |
for (name in object){ | |
if (object.hasOwnProperty(name)){ | |
// do stuff | |
} | |
} | |
// The above will fail if the object has a hasOwnProperty property. |
OlderNewer