Giter VIP home page Giter VIP logo

js.class's People

Contributors

dkraczkowski avatar fastrde avatar homer0 avatar yofreke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

js.class's Issues

Mixins example

var Pet = JSClass({
    name: function(name) {
        if (typeof name === 'undefined') {
            return this.name;
        }
        this.name = name;
    }
});
var Animal = Class({
    eat: function() {
        this.fed = true;
    },
    drink: function() {
        this.thirsty = false;
    }
});
var Dog = JSClass({
}).mixin(Pet, Animal);
var pluto = new Dog();
pluto.eat();
pluto.name('pluto');

console.log(pluto.name());//pluto
console.log(pluto.thirsty);//false

So I am a bit confused about this example (and a newbie so please forgive if the following is silly).

First, I think that 'var Animal = Class' should be var Animal =JSClass. If not, can you explain?

Second, as I understand it, a class provides methods that are inherited. So in the case of Pluto, he inherits the method eat via the mixin containing Animal. You then call the method pluto.eat() which assigns the property eat to Pluto. But you did not do that for drink. So shouldn't 'console.log(pluto.thirsty);//false' return 'undefined'?

super() function for ES5?

Reading through the documentation, it seems that the super() function is only supported for ES6?

If so, it would be super handy to have that function available for ES5 -- I know I've seen other JS class libs do it.

Get the "runtime" type of an object

Hi i have 2 classes A and B, B is a subclass of A.

var A = Class({});
var B = A.extend({});

If i want to test if my current object is actually of type A and not type B how would i do this without specificially checking that its not any of its subtypes:

var x = new A();
var y = new B();

x.typeOf(A); //true
x instanceof A; //true

y.typeOf(A); //true
y instanceof A; //true

So from my perspective i cant tell that x is of type A only, without starting to test for all the subclasses i dont want it to be.

in java i would do something like:

x.getClass() == A.class; //True
y.getClass() == A.class; //False (Since its class is B)

static doesn't capture the correct property name in Chrome

Running Chrome "Version 46.0.2490.71 m".

Minimal repro based on the code in the readme:

var StaticExample = JSClass({
    }).static({
        myStatic: 'myStatic',
        myStatic2: 'myStatic2'
    });
    console.log(StaticExample.myStatic);//myStatic2
    console.log(StaticExample.myStatic2);//myStatic2

[Feature Request] Get class object from an instance

Hi.
It would be so nice if we can retrieve the class object from an instance.
Like this:

var Dog = JSClass({
    ...
}).static({
    species: 'C. lupus'
});

var myPet = new Dog();
console.log( myPet.getClass().species ); // "C. lupus"

if (myPet.getClass() === Dog) { // true
    ...
}

Or can I already do the same thing somehow?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.