Skip to content

Instantly share code, notes, and snippets.

@kevinansfield
Created May 12, 2013 12:07
Show Gist options
  • Save kevinansfield/5563346 to your computer and use it in GitHub Desktop.
Save kevinansfield/5563346 to your computer and use it in GitHub Desktop.
+computed firstName, lastName
fullName: (key, value) ->
if arguments.length == 2 and value
name = value.split(' ')
@firstName = name[0]
@lastName = name.slice(1).join(' ')
if @firstName or @lastName
"#{@firstName} #{@lastName}"
else
null
fullName: Ember.computed(function (key, value) {
var name;
if (get$(arguments, 'length') === 2 && value) {
name = value.split(' ');
set$(this, 'firstName', name[0]);
set$(this, 'lastName', name.slice(1).join(' '));
}
if (get$(this, 'firstName') || get$(this, 'lastName')) {
return '' + get$(this, 'firstName') + ' ' + get$(this, 'lastName');
} else {
return null;
}
}).property('firstName', 'lastName')f
fullName: function(key, value) {
if (arguments.length === 2 && value) {
var name = value.split(' ');
this.set('firstName', name[0]);
this.set('lastName', name.slice(1).join(' '));
}
var firstName = this.get('firstName') || '';
var lastName = this.get('lastName') || '';
if (firstName || lastName) {
return firstName + ' ' + lastName;
} else {
return null;
}
}.property('firstName', 'lastName')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment