2014년 12월 29일 월요일

[AngularJS] Re: Simple domain model

If Class is contained inside a library file (.js), make sure that file is referenced in main .html. If running test on karma, make sure that .js is included in karma.conf

Em segunda-feira, 29 de dezembro de 2014 11h53min12s UTC-2, Mohan Radhakrishnan escreveu:
Hi,
 
             I would like to use Resig's method to use OO like this.
 
var User = Class.extend({

  init: function(firstName,lastName){

    this.firstName = firstName;
    this.lastName = lastName;

  },

  getFirstName: function(){

    return this.firstName;

  },
  getLastName: function(){

    return this.firstName;

  }

});
 
There are two questions.
Q1 :
How is the 'Class' framework code recognized by Angular ?
 
Q2:
When I code a jasmine test like this
 
describe("User's First Name", function() {
    it("firstName", function() {
        expect(new User("firstName","lastName").getFirstName()).toEqual("firstName");
    });
});
 
I get 'Uncaught ReferenceError: Class is not defined'
 
So I think I haven't understood how to make angular recognize the 'Class' framework code. I am trying to build a domain model.



I did that but then later just included two lines because all the requirements are in mainConfig.js. I think if the application uses requirejs properly then the karma ordering problems are solved.

      'vendor/requirejs/require.js',
      'js/mainConfig.js',


댓글 없음:

댓글 쓰기