Git Product home page Git Product logo

operator-overloading-js's People

Contributors

faleij 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  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  avatar  avatar

Watchers

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

operator-overloading-js's Issues

Assignment Operators are not working.

While the test passes they are all wrong for the assignment operators.
For example 'should overload += operator'

// test/tests.js #265
r += 33 + 22;
assertEqual(r, '33+33+22');

Should be

r += 33 + 22;
assertEqual(r, '33+22+=33');

as r += 33 + 22; should be interpretated as r = r.__addAssign(33..__plus(22));

I will be submitting a pull request for solving this after this issue is posted.

Alternative (escaping?) operator suggestion

Hello. I suggest alternative operator, that does not used in overloading.

c = a $[+] b; //Not overloadable operator, but this is plus

Also, how to overload assign operator?

Provide a functional interface which doesn't pollute Function.prototype

Kudos for this! It looks like a well-thought-out implementation which avoids the obvious gotchas and is mindful of the scoping/performance issues which plague other implementations[1], but I could never use it in a library or production code as it pollutes a native object (Function), which is considered a no-no in JavaScript.

Have you considered providing a functional interface as well/instead e.g.:

import overload from 'operator-overloading';

overload(() => {
    let c1 = new Complex(1, 2);
    let c2 = new Complex(3, 4);
    assert.equal(c1 + c2, '4+6i');
})();

The method could still be enabled explicitly e.g.:

require('operator-overloading/global');

1 Although, surprisingly, this article suggests the performance hit isn't that large...

overload functions don't fully apply

Hi,

The overload functions don't seem to be apply in all cases, e.g. if operators are used in an if condition, as in

if (a == b) { // ...

To fix this instance I added the following:

    case 'IfStatement':
        visit(statement.test, index, program);
        if (statement.consequent) visit(statement.consequent, index, program);
        if (statement.alternate) visit(statement.alternate, index, program);
        break;

to the switch under visit.

I have a similar problem with For loop code, the ternary statement. My quick attempts to fix didn't work here.

Is there an alternative way to ensure all possible Javascript operators are overloaded?

Thanks
Declan

No exported function overload in the browser using script tag

Hi, when I simply include dist/browser/overload.js of v. 0.5.1 via HTML script tag no overload function gets added to the global window object. Though the prototypes of Number, Function, Object ect. all get the double underscore operator methods.
I'd like to use the operator-overloading in my projects organized as AMD modules. To create an AMD module I could wrap the scripts in dist/browser, but no luck so far.

Version 0.4.4 from Bower Components is still usable in a browser environment, because it is based upon Function.prototype.enableOverloading and not on exported functions.

Arrow functions aren't supported

condition is arrow function for comfortable usage, but it doesn't work

type Where = (over: Over) => A
function where(condition: Where) {
  const o = new Over()

  const overloadedFunction = overload(condition)
  return overloadedFunction(o, condition)
}

const data = where(p => p.a1 || p.a2)

image

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.