8000 Return value of extend.myNamespace intentional? by jasonkarns · Pull Request #1 · searls/extend.js · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Return value of extend.myNamespace intentional? #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

jasonkarns
Copy link
Collaborator

Is there a use-case for returning the extend function itself from extend.myNamespace? Or was the return value chosen for lack of an alternative?

I ask, because of the use-case for returning the extended namespace instead:

window.myApp = extend.myNamespace({});

Perhaps a new method is in order?

window.myApp = extend.createNamespace();

@searls
Copy link
Owner
searls commented Jun 29, 2013

I didn't give a second thought to the return value of myNamespace since it's really just adds an extend method and (I believe?) throws things into a noConflict mode.

I'm not sure if the semantic difference of the above createNamespace is really worth it, but I don't think there's any harm in returning the extended object, that's for sure.

@jasonkarns
Copy link
Collaborator Author
  • return the namespace, not the #extend method itself
  • create the namespace if given undefined
  • update the shared examples to test the extender. (shared examples are defined before the result is set by beforeEach)

Utilizing the existing shared examples to test a variable that is
*created* during spec evaluation is impossible without lazy evaluation.
(Since the shared examples function accepts the variable in question and
essentially writes new examples with the variable in question already in
scope.) One way of getting around this is to hang all the
shared-examples-arguments off of a context object. This context object
is kept in scope via a closure in the example group. This allows any
necessary properties to be set on the context object during the course
of spec evaluation and they will be accessible in both the beforeEach
function and the shared examples because the context object is in scope
(via the closure).

However, the 'this' object (in Jasmine, the 'Spec' object) is shared
among all executing examples. Instead of creating a dummy context object
as a carrier, we can just hang any necessary arguments off of the Spec
object. And since this is in CoffeeScript, that's just a matter of
prefixing the shared variables with '@'.

Now shared examples are capable of testing variables that aren't
initialized (or modified) until spec execution; in other words, lazily
evaluated.
@jasonkarns
Copy link
Collaborator Author

Finally figured out a way to get the shared examples to test an extender that wasn't set until the spec runs by using the Spec object. This is ready for review, finally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0