Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8811033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:15:47+00:00 2026-06-14T03:15:47+00:00

I am newbie of JavaScript and studying with CoffeeScript. I want to make a

  • 0

I am newbie of JavaScript and studying with CoffeeScript. I want to make a class which communicate to Flickr Web API with Ajax when initialized.

class Photo

  json: null

  constructor: ->
    @getJson()

  _getJson: (data) ->
    @json = data.photos.photo

  getJson: ->
    $.ajax(
      url : 'http://www.flickr.com/services/rest/'
      type : 'GET'
      data :
        format : 'json'
        method : 'flickr.photos.search'
        api_key : 'api_key'
        user_id : '29242822@N00'
        per_page : '100'
      dataType : 'jsonp'
      jsonp : 'jsoncallback'
      success : @_getJson
    )

I wrote a Jasmine test which test the initialization of the class.

describe("Photo", ->
  photo = new Photo
  console.log(photo.json)
  it("should get json when constructed", ->
    expect(photo.json).toBeDefined()
  )
  it("should have json which begins", ->
    expect(photo.json[0].title).beBe('Ridges of Shirouma')
  )
)

But photo.json is always null.

Thank you for your kindness.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:15:49+00:00Added an answer on June 14, 2026 at 3:15 am

    $.ajax calls its callback functions in the context of a settings object:

    context Object

    This object will be made the context of all Ajax-related callbacks. By default, the context is an object that represents the ajax settings used in the call ($.ajaxSettings merged with the settings passed to $.ajax).

    So @ isn’t your Photo object in your callback, it is some settings object that is of little use to you. But, if you bind your _getJson to your Photo by defining it with a fat-arrow (=>):

    _getJson: (data) =>
      @json = data.photos.photo
    

    then @ will be your Photo and @json will end up being what you’re looking for.

    The next problem you’ll probably have is that your AJAX call won’t necessarily have returned when Jasmine tries to see if it worked. I’m not that familiar with Jasmine but there is this answer on testing AJAX with Jasmine that people seem to like; there’s also http://github.com/pivotal/jasmine-ajax for stubbing the AJAX part to avoid the asynchronous part.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a jquery/javascript newbie. What I want to do is add a class
hi i am newbie to javascript.... i want to synchronize scrolling of two select
I am basically a newbie with javascript. I want to populate a div in
I'm a total newbie and want to start with php. I know some javascript
i am newbie to javascript and i want to know how to set value
I'm a newbie to javascript (or web development of any sort, really), and having
I am web-designer, not a programmer and a newbie in Javascript / jQuery (although
I am newbie of JavaScript and studying with textbook. I wrote below code, and
I am newbie in javascript xml data handling. Currently, my ajax call to a
I'm a mostly-newbie Javascript'er and I'm trying it on a webpage which, upon pressing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.