Last active
August 29, 2015 14:06
-
-
Save moregeek/6a77aa1d4cf34a86ca16 to your computer and use it in GitHub Desktop.
CoffeeScript Class Example for "private" variables
This file contains hidden or 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
class CloneTest | |
constructor: (options = {}) -> | |
@default_options = { | |
foo: false, bar: false, baz: false | |
} | |
$.extend(@default_options, options) | |
getValues: -> | |
return JSON.stringify(@default_options, null, 4) | |
clone: (options = {}) -> | |
return new CloneTest( $.extend({}, @default_options, options) ) | |
obj_1 = new CloneTest() | |
console.log "============================ obj_1 ============================" | |
console.log "expected_values:", JSON.stringify({ foo: false, bar: false, baz: false}, null, 4) | |
console.log "----------------------------------------------------------------" | |
console.log "result_values: ", obj_1.getValues() | |
obj_2 = obj_1.clone(foo: true) | |
console.log "============================ obj_2 ============================" | |
console.log "expected_values:", JSON.stringify({ foo: true, bar: false, baz: false}, null, 4) | |
console.log "----------------------------------------------------------------" | |
console.log "result_values: ", obj_2.getValues() | |
obj_3 = obj_1.clone(bar: true) | |
console.log "============================ obj_3 ============================" | |
console.log "expected_values:", JSON.stringify({ foo: false, bar: true, baz: false}, null, 4) | |
console.log "----------------------------------------------------------------" | |
console.log "result_values: ", obj_3.getValues() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment