Skip to content

Instantly share code, notes, and snippets.

View aarongough's full-sized avatar

Aaron Gough (He/Him) aarongough

View GitHub Profile
if( object.property )
{
var result = object.property;
}
else
{
var result = object.otherProperty;
}
var result = (object.property) ? object.property : object.otherProperty;
var result = object.property || object.otherProperty;
window.firstProperty = "Hello!";
window.secondProperty = "I'm number 2!";
var result = window.firstProperty || window.secondProperty;
alert( result ); // Hello!
// window.firstProperty === undefined;
window.secondProperty = "I'm number 2!";
var result = window.firstProperty || window.secondProperty;
alert( result ); // I'm number 2!
var viewportHeight = self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
// ^ FF, Safari, Opera ^ IE6 Strict ^ All other explorers
require 'test/unit'
class SanityTest < Test::Unit::TestCase
def test_my_sanity
complex_array = [{:blah => "hello"},{:foo => "blah"}]
copied_array = complex_array
copied_array[0][:blah] = nil
assert_not_equal copied_array, complex_array
end
require 'test/unit'
class SanityTest < Test::Unit::TestCase
def test_my_sanity
complex_array = [{:blah => "hello"},{:foo => "blah"}]
copied_array = complex_array.clone
copied_array[0][:blah] = nil
assert_not_equal copied_array, complex_array
end
require 'test/unit'
class ShallowTest < Test::Unit::TestCase
def test_standard_copy_should_be_by_reference_and_changes_should_back_propagate
simple_array = [1,"hello", 3.000]
copied_array = simple_array
copied_array[0] = nil
copied_array[1] = nil
copied_array[2] = nil
require 'test/unit'
class FinallySaneTest < Test::Unit::TestCase
def test_deep_copy
complex_array = [{:blah => "hello"},{:foo => "blah"}]
copied_array = Marshal.load(Marshal.dump(complex_array))
copied_array[0][:blah] = nil
assert_not_equal copied_array, complex_array
end