Browse Source

Cast function inside script property to string

pull/67/head
Artur Arseniev 9 years ago
parent
commit
84d5b027b2
  1. 6
      src/demo.js
  2. 21
      src/dom_components/model/Component.js

6
src/demo.js

@ -414,6 +414,7 @@ require(['config/require-config'], function() {
switchTime: 3000, // Switch time
animSpeed: 600, // Animation Speed/Duration
droppable: false,
script : function () {console.log(5);},
traits: [{
type: 'number',
label: 'Duration',
@ -433,6 +434,11 @@ require(['config/require-config'], function() {
}),
init: function () {
this.listenTo(this, 'change:status',function(){
var obj = this.toJSON();
console.log(obj);
console.log(obj.script);
});
this.listenTo(this, 'change:animSpeed change:autoRotation change:switchTime',
this.buildScript);
},

21
src/dom_components/model/Component.js

@ -290,6 +290,27 @@ define(['backbone','./Components', 'SelectorManager/model/Selectors', 'TraitMana
return attr;
},
/**
* Return a shallow copy of the model's attributes for JSON
* stringification.
* @return {Object}
* @private
*/
toJSON: function() {
var obj = Backbone.Model.prototype.toJSON.apply(this, arguments);
var script = this.get('script');
// Need to cast script functions to string
if (typeof script == 'function') {
var scrStr = script.toString();
scrStr = scrStr.replace(/^function\s?\(\)\s?\{/, '');
scrStr = scrStr.replace(/\}$/, '');
obj.script = scrStr;
}
return obj;
},
},{
/**

Loading…
Cancel
Save