Skip to content

Instantly share code, notes, and snippets.

View ElliotChong's full-sized avatar
✌️

Elliot Chong ElliotChong

✌️
View GitHub Profile
@ElliotChong
ElliotChong / proxy.js
Created September 4, 2012 17:57
JavaScript implementation of a Proxy class.
/**
* JavaScript implementation of a Proxy class.
**/
​function Proxy(p_target)
{
var self = this;
self.target = p_target;
// Access target's properties
self.get = function (p_property)
@ElliotChong
ElliotChong / Gruntfile.coffee
Created November 14, 2013 17:20
Example Gruntfile showing concurrent CoffeeScript > JS > minification, SASS > CSS > minification, livereload, and nodemon / nodeinspector tandem.
module.exports = (grunt) ->
config =
browserify:
development:
options:
transform: ["coffeeify"]
debug: true
files:
"./public/scripts/editor.js": ["./frontend/scripts/editor.coffee"]
uglify:
@ElliotChong
ElliotChong / underscore.mixin.deepExtend.coffee
Last active November 28, 2020 23:55
Copy all of the properties in the source objects over to the destination object, and return the destination object. This method will recursively copy mutual properties which are also objects.
# Create a deep copy of an object. - CoffeeScript conversion of @cederberg's deepClone implementation https://github.com/documentcloud/underscore/pull/595
deepClone = (obj) ->
if !_.isObject(obj) or _.isFunction(obj) then return obj
if _.isDate obj then return new Date do obj.getTime
if _.isRegExp obj then return new RegExp obj.source, obj.toString().replace(/.*\//, "")
isArr = _.isArray obj or _.isArguments obj
func = (memo, value, key) ->
if isArr then memo.push deepClone value