Created
June 1, 2011 17:58
-
-
Save fogus/1002886 to your computer and use it in GitHub Desktop.
mvf.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var M = function() { this.m = function() { return 42 } }; | |
var inst = new M(); | |
inst.f = function() { return 42 }; | |
// How to tell that f is a function in a field and | |
// m is a method in an *arbitrary* object? | |
// | |
// example: | |
is_method(inst.f); | |
//=> false | |
is_method(inst.m); | |
//=> true | |
// Is it possible to write is_method? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In your example, the method assignments are functionally equivalent --
this
in the constructor is going to be==
yourinst
; the interpreter doesn't keep track of ("doesn't care") whether the value at a given field is assigned as part of the constructor's operation, or if it's assigned later. So the short answer is: "No, you can't write anis_method
."What you're looking for is probably something more like this: