0

I am trying to loop through an array with CoffeeScript to pull out the full_name value as shown below. I've been all over Stack overflow and CoffeeScript's docs the last few days and can't figure it out. This is what I currently have. Can you tell me what I'm doing wrong?

Angular JS

<disabled-display template="{{ctrl.getTechnicianNames()}}">

CoffeeScript

ctrl.getTechnicianNames = (full_name) ->
    array_of_persons = ctrl.technicians
    ctrl.getTechnicianNames full_name for full_name in array_of_persons

ctrl.technicians

{email: "[email protected]", first_name: "John", full_name: "John Johnson",
last_name: "Johnson"}, 
{email: "[email protected]", first_name: "Frank", full_name: "Frank Franklin",
last_name: "Franklin"}

2 Answers 2

2

There is a much more coffeescripty way:

ctrl.technitianNames = -> (t.full_name for t in @technicians)

Note the avoidance of the get prefix. It is considered a code smell in (to my knowledge most) languages other than Java and C++.

Sign up to request clarification or add additional context in comments.

2 Comments

Note I dropped the get prefix b/c to my best knowledge it tends to be a code smell in languages other than Java and C++.
Yes! I assumed this was part of your decision. I ended up using show instead of get, but that could also be a code smell!
1
ctrl.getTechnicianNames = ->
    ctrl.technicians.map((technician) => technician.full_name)

Nothing specific to CoffeeScript about it, you just want Array.prototype.map: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.