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
| if( object.property ) | |
| { | |
| var result = object.property; | |
| } | |
| else | |
| { | |
| var result = object.otherProperty; | |
| } |
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
| var result = (object.property) ? object.property : object.otherProperty; |
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
| var result = object.property || object.otherProperty; |
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
| window.firstProperty = "Hello!"; | |
| window.secondProperty = "I'm number 2!"; | |
| var result = window.firstProperty || window.secondProperty; | |
| alert( result ); // Hello! |
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
| // window.firstProperty === undefined; | |
| window.secondProperty = "I'm number 2!"; | |
| var result = window.firstProperty || window.secondProperty; | |
| alert( result ); // I'm number 2! |
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
| var viewportHeight = self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; | |
| // ^ FF, Safari, Opera ^ IE6 Strict ^ All other explorers |
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
| 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 |
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
| 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 |
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
| 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 | |
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
| 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 |
OlderNewer