Closed adwydman closed 8 years ago
Great Idea!
new function
s are replaced in this branch, it'll be a good merge candidate :)This is unnecessary, as JavaScript supports closerues, therefore functions remember the environment they were created in.
And, in order to ease unit testing, we should minimize usage of private properties overall (not that we have that many, anyway)
I have rewritten every file I found. The exception is core.js
, because it will probably be deleted.
@kuba-orlik It's ready to be reviewed.
Hmmm I've tried running the tests locally and they failed:
> sealious@0.7.11 test /home/kuba/projects/sealcode/sealious/sealious
> mocha --recursive tests
/home/kuba/projects/sealcode/sealious/sealious/lib/subject/predefined-subjects/me-subject.js:12
MeSubject.prototype = Object.create(Sealious.Subject.prototype);
^
TypeError: Cannot read property 'prototype' of undefined
at Object.<anonymous> (/home/kuba/projects/sealcode/sealious/sealious/lib/subject/predefined-subjects/me-subject.js:12:53)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:456:32)
at tryModuleLoad (module.js:415:12)
at Function.Module._load (module.js:407:3)
at Module.require (module.js:466:17)
at require (internal/module.js:20:19)
Could you look into it? Does it fail for you, as well?
I cannot recreate this error, as the test pass:
$ npm test
> sealious@0.7.11 test C:\Users\anwi\Desktop\sealious
> mocha --recursive tests
AccessStrategy.Logged_In
√ returns the name of the access strategy
√ resolves the checker function
√ rejects the checker function
AccessStrategy.Noone
√ returns the name of the access strategy
√ rejects the checker_function
√ checks item_sensitive atribute
(...)
Hmmm... I've removed the node_modules
directory and reinstalled all of the dependencies. Few checks:
node_modules
directory and reinstall all dependencies?Hm, after deleting node_modules
, I have the same error.
Please merge the references
branch to rewrite_new_function_to_object
it will bring the locreq
changes, possibly helping with those cyclic dependencies.
Tests pass after merging references
to this branch.
Here is my proposition: rewriting
new function
to object literals/assignments.Why?
Basically Sealious uses
new function
on two different occasions:The main goal of that approach was to hide the private fields and expose only the public ones like this:
This is unnecessary, as JavaScript supports closerues, therefore functions remember the environment they were created in. The above example work the same as this one:
Prototypes
The same applies to prototypes, plus one more thing:
This prototype is overwritten by the
new function
provided and I wonder if this is the best idea.Summary
We spoke about this before and maybe the time has come to rewrite
new function
. :) Let me know what you think. If the response is positive, I will carry on.