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

  • SEARCH
  • Home
  • 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 8870373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:42:40+00:00 2026-06-14T17:42:40+00:00

I am newbie of JavaScript. I want to make a class which communicate to

  • 0

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

Photo2.js

  var Photo2;

  Photo2 = (function() {

    Photo2.prototype.json = null;

    function Photo2() {
      $.getJSON('http://www.flickr.com/services/rest/?jsoncallback=?', {
        format: 'json',
        method: 'flickr.photos.search',
        api_key: '7965a8bc5a2a88908e8321f3f56c80ea',
        user_id: '29242822@N00',
        per_page: '100'
      }, function(data) {
        this.json = data.photos.photo;
      });
    }

    return Photo2;

  })();

But when initialized as photo2 = new Photo2 this does not have photo2.json.

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-14T17:42:42+00:00Added an answer on June 14, 2026 at 5:42 pm

    You should really rewrite your code. It’s complicated and hard to figure out what you’d like to achieve.

    First of all, getting data from server is asynchronous so you cannot be sure that after creating an instance of Photo2 json property will be defined.

    Next things is that it’s really bad idea to make server call while initializing an object. I advice you following solution:

    (function() {
      var Photo2 = function(callback) {
        this.json = null;
      };
    
      Photo2.prototype.getData =  function(successCallback) {
        var self = this;
    
        $.getJSON('http://www.flickr.com/services/rest/?jsoncallback=?', {
            format: 'json',
            method: 'flickr.photos.search',
            api_key: '7965a8bc5a2a88908e8321f3f56c80ea',
            user_id: '29242822@N00',
            per_page: '100'
          }, function(data) {
            self.json = data.photos.photo;
            typeof successCallback == 'function' && successCallback();
          }); 
      };
    
      var photo = new Photo2();
      photo.getData(function successCallback() {
        console.log('Data loaded', photo.json);
      });
    }).call(this);
    

    Working demo here: http://jsbin.com/ureyas/1/edit

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

Sidebar

Related Questions

I am newbie of JavaScript and studying with CoffeeScript. I want to make a
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 web development world. Let me explain what i want. id
I am web-designer, not a programmer and a newbie in Javascript / jQuery (although
I am a Selenium newbie ... As a JavaScript programmer, I think I want
I'm a newbie in JavaScript. I have a function that is supposed to loop

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.