SteveSanderson/knockout.mapping — pull request #167 by traviskaufman (2013-07-15 01:27:52+00:00)
Title: Add cross-frame compatibility to knockout.mapping

I was using knockout.mapping on a project where the plugin needed to be loaded within a sandboxed environment (in this case, an iframe) and noticed that it was in no way behaving as expected. This seemed to be due to two things:

1. `exports.getType` was looking at an object's constructor to determine what kind of object it was.
2. There was some use of the `instanceof` operator for type inference.

Because of these, the library would not work unless loaded within the same window context as the script in which it was being used. This PR fixes that issue by using `Object.prototype.toString` to find the internal `[[Class]]` property of the object (as per [the ECMA spec](http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.4.2)) and return the proper value from there.

Note that with the current implementation `getType` will return "object" when passed `null`. I'm not sure if this is the behavior that you're looking for since in most cases a client doesn't treat a "null" property the same way it treats other objects, but I left it since it's outside the scope of this PR. Happy to add it though if you guys would like! I tried it out and ran the QUnit suite and everything still passed.

p.s. AWESOME knockout plugin! Made my life a whole lot easier for this project!