Closed podhmo closed 7 years ago
class Range(object):
def __new__(cls, range_, loose):
if isinstance(range_, Range) and range_.loose == loose:
return range_
return super().__new__(cls)
this is not good. for complete porting.
function Range(range, loose) {
if (range instanceof Range) {
if (range.loose === loose) {
return range; // b.
} else {
return new Range(range.range, loose) //b2.
}
}
if (!(this instanceof Range))
return new Range(range, loose); // c.
// d.
this.loose = loose;
this.raw = range;
// do something
}
and, b2 path's code is not ported by this method.
define function such like below.
I have defined these functions for js and python compatibility. but these are needless.
using
__new__()