Q:

writing a CoffeeScript Class

I have the following simple CoffeeScript Class:
class Country
    constructor: (@val) ->
        console.log @val
    foreign: ->
        @val isnt "United States"
    domestic: ->
        not foreign()

I have this simple class to determine some logic for a select drop down.
Here is how I am calling it:
$country = new Country($val) if $('select[id*="country"]').val() > 0
console.log $country.foreign? if $country?

$val is being set in an on('change') event. $country.foreign? is always evaluating to true even if I select a country other than the US. Not sure what I am doing wrong here. The @val is being set to the value I am passing in, but the foreign function isn't working properly

A:

It should be
console.log $country.foreign()? if $country?

foreign is a function call.
Also that translates to this:
if (typeof $country !== "undefined" && $country !== null) {
  console.log($country.foreign() != null);
}

So you get a log of whether or not the return is null, you probably want to drop the ?
console.log $country.foreign() if $country?

