in my DOM I see this
<script type="te开发者_如何学Cxt/javascript">
$(document).ready(function(){
Test.js({"Now":"\/customers\/product\/1","id":"29scds","pro_id":"124""});
});
</script>
i need to alert out the values in Test.js
from another javascript page thats included in the DOM. How can I do that
thanks
EDIT
alert(Test.js)
gave this
function (params) {
for (var prop in params) {
this[prop] = params[prop];
}
}
The Test.js
function that you posted is assigning the properties of the object passed in to it to become properties of this
which is the object Test
. Assuming the Test
object is available in your scope, you can alert the values as follows:
for (var p in Test) {
if (Test.hasOwnProperty(p) && typeof(Test[p]) !== "function") {
alert(p + " is " + Test[p]);
}
}
See simplified example →
It seems to me that Test.js just copies properties from one object to another. It should have a hasOwnProperty
filter, but it doesn't. The following might help:
function showObj(o) {
var r = [];
for (var p in o) {
if (o.hasOwnProperty(p)) {
r.push(p + ': ' + o[p]);
}
}
alert(r.join('\n'));
}
function test (params) {
for (var prop in params) {
this[prop] = params[prop];
}
}
var o = {foo:'foo',bar:'bar'};
showObj(o);
var a = {}
test.call(a,o);
showObj(a);
精彩评论