in reply to Re^4: Refactoring technique?
in thread Refactoring technique?
Lucky for you that want the oo[a] notation instead of oo.x notation. I am mostly positive that Javascript cannot interpolate a method call at runtime. Consider the following:
When run, do_meth returns "wrong key!" instead of 123. You have to hard code return obj.id ... or use bracket notation such as you desire.#!/usr/bin/node var key = 'id'; var obj = { id: 123, key: "wrong key!" }; function do_meth( obj, key ) { return obj.key; } function do_windex( obj, key ) { return obj[key]; } console.log( do_meth( obj, key ) ); console.log( do_windex( obj, key ) );
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Refactoring technique?
by BrowserUk (Patriarch) on Apr 24, 2015 at 22:36 UTC |