Skip to content

Instantly share code, notes, and snippets.

@mkuklis
mkuklis / gist:997928
Created May 29, 2011 16:38
JavaScript passed by value or reference
// primitives are passed by value
var a = 4;
function fn1(val) {
val = 5;
}
fn1(a);
alert(a) // still 4
// objects are passed by reference
var o = {a: 4};
@mkuklis
mkuklis / gist:959363
Created May 6, 2011 17:16
prototype, __proto__ & constructor in JS
var Foo1 = function() {};
var Foo2 = function() {};
var foo1 = new Foo1();
console.log(foo1.constructor == Foo1.prototype.constructor) // true
console.log(Foo1.prototype.constructor == Foo1) // true
console.log(foo1.constructor == Foo1) // true
console.log(foo1.constructor == foo1.__proto__.constructor) // true
console.log(foo1.__proto__.constructor == Foo1) // true
function Foo() {};
Foo.prototype = {};
var foo = new Foo();
foo.__proto__ == Foo.prototype; // true
@mkuklis
mkuklis / chain.js
Created February 27, 2011 01:11
chain
function chain() {
var cur = prev = null;
for (var i = l = arguments.length - 1; i >= 0; i--) {
prev = cur;
cur = (function(params) {
return function() {
for (var param in params) {
this[param] = params[param];
}
}
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
a {
text-decoration:none;
}
a:hover {
text-decoration:none;
}
<!-- message -->
<cfoutput>#createMessage("Name", "$490.00", "Health Care", "Solar Home Systems", "Koni, Ghana")#</cfoutput>
<br /><br />
<!-- facebook -->
<a name="fb_share" share_url="http://www.energyincommon.org" type="button">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>
<br /><br />
<!-- twitter -->
<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.energyincommon.org" data-text="<cfoutput>#createMessage("Name", "$490.00", "Health Care", "Solar Home Systems", "Koni, Ghana")#</cfoutput>" data-count="horizontal" data-via="energyincommon">Tweet</a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
@mkuklis
mkuklis / gist:744463
Created December 17, 2010 03:55
message for twitter/facebook
<cffunction name="createMessage">
<cfargument name="name" required="true" type="string">
<cfargument name="amount" required="true" type="string">
<cfargument name="activity" required="true" type="string">
<cfargument name="technology" required="true" type="string">
<cfargument name="location" required="true" type="string">
<cfreturn "Help " & name & " collect " & amount & " for " & technology & " (" & activity & ") in " & location>
</cffunction>
@mkuklis
mkuklis / gist:743062
Created December 16, 2010 05:11
cf9 function usage
<!DOCTYPE html>
<html>
<head></head>
<body>
<a href="http://twitter.com/share" class="twitter-share-button"
data-url="http://www.energyincommon.org"
data-text="<cfoutput>#createTwitterMessage("Frist Name Last Name", "$490.00", "Health Care", "Solar Home Systems", "Koni, Ghana")#</cfoutput>"
data-count="horizontal" data-via="energyincommon">Tweet</a>
<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
</body>
@mkuklis
mkuklis / gist:743060
Created December 16, 2010 05:09
cf9 test
<cfscript>
// creates message ready for Twitter for given paramaters
function createTwitterMessage(name, amount, activity, technology, location) {
return "Help " & name & " collect " & amount & " for " & activity & " in " & location;
}
</cfscript>